/**
     * Sale price field.
     *
     * Display the simple sale price field below the normal price field.
     *
     * @since 1.0.0
     *
     * @param int $post_id ID of the current download being edited.
     */
    public function simple_sale_price_field($post_id)
    {
        $price = edd_get_download_price($post_id);
        $sale_price = get_post_meta($post_id, 'edd_sale_price', true);
        $variable_pricing = edd_has_variable_prices($post_id);
        $prices = edd_get_variable_prices($post_id);
        $single_option_mode = edd_single_price_option_mode($post_id);
        $price_display = $variable_pricing ? ' style="display:none;"' : '';
        $variable_display = $variable_pricing ? '' : ' style="display:none;"';
        ?>
<div id="edd_regular_sale_price_field" class="edd_pricing_fields" <?php 
        echo $price_display;
        ?>
><?php 
        $price_args = array('name' => 'edd_sale_price', 'value' => !empty($sale_price) ? esc_attr(edd_format_amount($sale_price)) : '', 'class' => 'edd-price-field edd-sale-price-field');
        $currency_position = edd_get_option('currency_position');
        if (empty($currency_position) || $currency_position == 'before') {
            echo edd_currency_filter('') . ' ' . EDD()->html->text($price_args) . ' ';
        } else {
            echo EDD()->html->text($price_args) . ' ' . edd_currency_filter('') . ' ';
        }
        ?>
<label class="edd-label" for="edd_sale_price"><?php 
        _e('Sale price', 'edd-sale-price');
        ?>
</label>&nbsp;<?php 
        ?>
</div><?php 
    }
/**
 * Render Download Columns
 *
 * @since 1.0
 * @param string $column_name Column name
 * @param int $post_id Download (Post) ID
 * @return void
 */
function edd_render_download_columns($column_name, $post_id)
{
    if (get_post_type($post_id) == 'download') {
        global $edd_options;
        $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button';
        $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue';
        $purchase_text = !empty($edd_options['add_to_cart_text']) ? $edd_options['add_to_cart_text'] : __('Purchase', 'edd');
        switch ($column_name) {
            case 'download_category':
                echo get_the_term_list($post_id, 'download_category', '', ', ', '');
                break;
            case 'download_tag':
                echo get_the_term_list($post_id, 'download_tag', '', ', ', '');
                break;
            case 'price':
                if (edd_has_variable_prices($post_id)) {
                    echo edd_price_range($post_id);
                } else {
                    echo edd_price($post_id, false);
                    echo '<input type="hidden" class="downloadprice-' . $post_id . '" value="' . edd_get_download_price($post_id) . '" />';
                }
                break;
            case 'sales':
                echo edd_get_download_sales_stats($post_id);
                break;
            case 'earnings':
                echo edd_currency_filter(edd_format_amount(edd_get_download_earnings_stats($post_id)));
                break;
            case 'shortcode':
                echo '[purchase_link id="' . absint($post_id) . '" text="' . esc_html($purchase_text) . '" style="' . $style . '" color="' . esc_attr($color) . '"]';
                break;
        }
    }
}
function if_download_price_function($atts, $content)
{
    $atts = shortcode_atts(array('not' => 'no', 'id' => '', 'equals' => '', 'greater' => '', 'less' => ''), $atts, 'if_download_price');
    if ($atts['id'] != '') {
        $id = $atts['id'];
    } else {
        $id = get_the_id();
    }
    ob_start();
    $price = '';
    if (edd_has_variable_prices($id)) {
        $get_default_price = edd_get_default_variable_price($id);
        $prices = edd_get_variable_prices($id);
        $price = $prices[$get_default_price]['amount'];
    } else {
        $price = edd_get_download_price($id);
    }
    if ($atts['not'] == 'yes' || $atts['not'] == '1') {
        if (!eval_condition($price, $atts['equals'], $atts['greater'], $atts['less'])) {
            echo do_shortcode($content);
        } else {
            echo '';
        }
    } else {
        if (eval_condition($price, $atts['equals'], $atts['greater'], $atts['less'])) {
            echo do_shortcode($content);
        } else {
            echo '';
        }
    }
    return ob_get_clean();
}
/**
 * Price
 *
 * Displays a formatted price for a download.
 *
 * @access      public
 * @since       1.0
 * @param       int $download_id the ID of the download price to show
 * @param		bool whether to echo or return the results
* @return       void
*/
function edd_price($download_id, $echo = true)
{
    if (edd_has_variable_prices($download_id)) {
        $prices = edd_get_variable_prices($download_id);
        // return the lowest price
        $price_float = 0;
        foreach ($prices as $key => $value) {
            if ((double) $prices[$key]['amount'] < $price_float or $price_float == 0) {
                $price_float = (double) $prices[$key]['amount'];
            }
        }
        $price = edd_sanitize_amount($price_float);
    } else {
        $price = edd_get_download_price($download_id);
    }
    if (edd_use_taxes() && edd_taxes_on_prices()) {
        $price += edd_calculate_tax($price);
    }
    $price = apply_filters('edd_download_price', $price, $download_id);
    $price = '<span class="edd_price" id="edd_price_' . $download_id . '">' . $price . '</span>';
    if ($echo) {
        echo $price;
    } else {
        return $price;
    }
}
/**
 * Render Donwload Columns
 *
 * Render the custom columns content.
 *
 * @access      private
 * @since       1.0 
 * @return      void
*/
function edd_render_download_columns($column_name, $post_id)
{
    if (get_post_type($post_id) == 'download') {
        $sales = edd_get_download_sales_stats($post_id);
        $earnings = edd_get_download_earnings_stats($post_id);
        $color = get_post_meta($post_id, '_edd_purchase_color', true);
        $color = $color ? $color : 'blue';
        $purchase_text = get_post_meta($post_id, '_edd_purchase_text', true);
        $purchase_text = $purchase_text && '' !== $purchase_text ? $purchase_text : __('Purchase', 'edd');
        switch ($column_name) {
            case 'download_category':
                echo get_the_term_list($post_id, 'download_category', '', ', ', '');
                break;
            case 'download_tag':
                echo get_the_term_list($post_id, 'download_tag', '', ', ', '');
                break;
            case 'price':
                echo edd_price($post_id, false);
                if (!edd_has_variable_prices($post_id)) {
                    echo '<input type="hidden" class="downloadprice-' . $post_id . '" value="' . edd_get_download_price($post_id) . '" />';
                }
                break;
            case 'sales':
                echo $sales;
                break;
            case 'earnings':
                echo edd_currency_filter($earnings);
                break;
            case 'shortcode':
                echo '[purchase_link id="' . absint($post_id) . '" text="' . esc_html($purchase_text) . '" style="button" color="' . esc_attr($color) . '"]';
                break;
        }
    }
}
function if_download_lowest_price_function($atts, $content)
{
    $atts = shortcode_atts(array('not' => 'no', 'id' => '', 'equals' => '', 'greater' => '', 'less' => ''), $atts, 'if_download_price_lowest');
    if ($atts['id'] != '') {
        $id = $atts['id'];
    } else {
        $id = get_the_id();
    }
    ob_start();
    $price = '';
    $price = edd_get_download_price($id);
    // echo $price;
    if ($atts['not'] == 'yes' || $atts['not'] == '1') {
        if (!eval_condition($price, $atts['equals'], $atts['greater'], $atts['less'])) {
            echo do_shortcode($content);
        } else {
            echo '';
        }
    } else {
        if (eval_condition($price, $atts['equals'], $atts['greater'], $atts['less'])) {
            echo do_shortcode($content);
        } else {
            echo '';
        }
    }
    return ob_get_clean();
}
function download_lowest_price_function($atts)
{
    $atts = shortcode_atts(array('limit' => -1, 'id' => ''), $atts, 'download_price_lowest');
    if ($atts['id'] != '') {
        $id = $atts['id'];
    } else {
        $id = get_the_id();
    }
    return edd_currency_filter(edd_format_amount(edd_get_download_price($id, false)));
}
Пример #8
0
 /**
  * Setup the variable and prices properties
  *
  * @since 0.0.9
  *
  * @access protected
  */
 protected function set_price()
 {
     if (edd_has_variable_prices($this->product->ID)) {
         $this->variable = true;
         $this->prices = edd_get_variable_prices($this->product->ID);
     } else {
         $this->variable = false;
         $this->prices = edd_get_download_price($this->product->ID);
     }
 }
Пример #9
0
/**
 * Change the button text of a free download. Default is "Free - Add to Cart"
 *
 * @since 1.0.0
 */
function edd_wp_downloads_text_args($args)
{
    $free_download_text = edd_get_option('edd_wp_downloads_button_text', __('Free Download', 'edd-wp-downloads'));
    $variable_pricing = edd_has_variable_prices($args['download_id']);
    if ($args['price'] && $args['price'] !== 'no' && !$variable_pricing) {
        $price = edd_get_download_price($args['download_id']);
        if (0 == $price) {
            $wp_downloads_url = get_post_meta($args['download_id'], '_edd_wp_downloads_url', true);
            if ($wp_downloads_url) {
                $args['text'] = $free_download_text;
            }
        }
    }
    return $args;
}
/**
 * edd_rp_generate_stats
 *
 * Generates the full relational data array for all downloads
 * *
 * @since       1.0
*/
function edd_rp_generate_stats()
{
    $defaults = array('number' => 250);
    // Data is acquired from the most recent 250 purchase logs to protect performance. If you need to increase or decrease this, use the following filter
    $log_query = apply_filters('edd_rp_log_query_args', $defaults);
    $edd_payments_query = new EDD_Payments_Query($log_query);
    $edd_payments = $edd_payments_query->get_payments();
    // Determine what users have purchased what products
    if (!empty($edd_payments)) {
        foreach ($edd_payments as $payment) {
            $user_email = strtolower($payment->user_info['email']);
            $cart_items = $payment->cart_details;
            if (is_array($cart_items)) {
                foreach ($cart_items as $item) {
                    $logs_data[md5($user_email)][] = $item['id'];
                }
            }
        }
        foreach ($logs_data as &$log) {
            $log = array_unique($log);
        }
        // Itterate through each download and find users who have purchased it, then if they have purhcased any other downloads
        // add those to the count.
        $downloads = get_posts(array('post_type' => 'download', 'posts_per_page' => '-1', 'fields' => 'ids'));
        $relation_array = array();
        $display_free = edd_get_option('edd_rp_show_free', 1);
        foreach ($downloads as $download) {
            $relation_array[$download] = array();
            foreach ($logs_data as $log) {
                if (in_array($download, $log)) {
                    foreach ($log as $item) {
                        if ($display_free && !edd_has_variable_prices($item) && absint(edd_get_download_price($item)) === 0) {
                            continue;
                        }
                        if (!isset($relation_array[$download][$item])) {
                            $relation_array[$download][$item] = 0;
                        }
                        $relation_array[$download][$item]++;
                    }
                }
            }
            // Since the data inherintly includes itself in it's own array, just unset it.
            unset($relation_array[$download][$download]);
            arsort($relation_array[$download]);
        }
        update_option('_edd_rp_master_array', $relation_array);
    }
}
/**
 * Render Download Columns
 *
 * @since 1.0
 * @param string $column_name Column name
 * @param int $post_id Download (Post) ID
 * @return void
 */
function edd_render_download_columns($column_name, $post_id)
{
    if (get_post_type($post_id) == 'download') {
        global $edd_options;
        $style = isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button';
        $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue';
        $color = $color == 'inherit' ? '' : $color;
        $purchase_text = !empty($edd_options['add_to_cart_text']) ? $edd_options['add_to_cart_text'] : __('Purchase', 'edd');
        switch ($column_name) {
            case 'download_category':
                echo get_the_term_list($post_id, 'download_category', '', ', ', '');
                break;
            case 'download_tag':
                echo get_the_term_list($post_id, 'download_tag', '', ', ', '');
                break;
            case 'price':
                if (edd_has_variable_prices($post_id)) {
                    echo edd_price_range($post_id);
                } else {
                    echo edd_price($post_id, false);
                    echo '<input type="hidden" class="downloadprice-' . $post_id . '" value="' . edd_get_download_price($post_id) . '" />';
                }
                break;
            case 'sales':
                if (current_user_can('view_product_stats', $post_id)) {
                    echo '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-reports&tab=logs&view=sales&download=' . $post_id)) . '">';
                    echo edd_get_download_sales_stats($post_id);
                    echo '</a>';
                } else {
                    echo '-';
                }
                break;
            case 'earnings':
                if (current_user_can('view_product_stats', $post_id)) {
                    echo '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-reports&view=downloads&download-id=' . $post_id)) . '">';
                    echo edd_currency_filter(edd_format_amount(edd_get_download_earnings_stats($post_id)));
                    echo '</a>';
                } else {
                    echo '-';
                }
                break;
            case 'shortcode':
                echo '[purchase_link id="' . absint($post_id) . '" text="' . esc_html($purchase_text) . '" style="' . $style . '" color="' . esc_attr($color) . '"]';
                break;
        }
    }
}
/**
 * Get final price of a download after discount
 * 
 * Modified From:
 * includes/download-functions.php -> edd_price()
 * Modified Parts:
 * Remove the price as a number, without the html formatting.
 * 
 * @param  int   $download_id ID of the download
 * @return float              Download price
 */
function vp_edd_fd_get_calculated_price($download_id)
{
    if (edd_has_variable_prices($download_id)) {
        $prices = edd_get_variable_prices($download_id);
        // Return the lowest price
        $price_float = 0;
        foreach ($prices as $key => $value) {
            if ((double) $prices[$key]['amount'] < $price_float or $price_float == 0) {
                $price_float = (double) $prices[$key]['amount'];
            }
        }
        $price = edd_sanitize_amount($price_float);
    } else {
        $price = edd_get_download_price($download_id);
    }
    if (edd_use_taxes() && edd_taxes_on_prices()) {
        $price += edd_calculate_tax($price);
    }
    return $price;
}
/**
 * Render Download Columns
 *
 * @since 1.0
 * @param string $column_name Column name
 * @param int $post_id Download (Post) ID
 * @return void
 */
function edd_render_download_columns($column_name, $post_id)
{
    if (get_post_type($post_id) == 'download') {
        switch ($column_name) {
            case 'download_category':
                echo get_the_term_list($post_id, 'download_category', '', ', ', '');
                break;
            case 'download_tag':
                echo get_the_term_list($post_id, 'download_tag', '', ', ', '');
                break;
            case 'price':
                if (edd_has_variable_prices($post_id)) {
                    echo edd_price_range($post_id);
                } else {
                    echo edd_price($post_id, false);
                    echo '<input type="hidden" class="downloadprice-' . $post_id . '" value="' . edd_get_download_price($post_id) . '" />';
                }
                break;
            case 'sales':
                if (current_user_can('view_product_stats', $post_id)) {
                    echo '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-reports&tab=logs&view=sales&download=' . $post_id)) . '">';
                    echo edd_get_download_sales_stats($post_id);
                    echo '</a>';
                } else {
                    echo '-';
                }
                break;
            case 'earnings':
                if (current_user_can('view_product_stats', $post_id)) {
                    echo '<a href="' . esc_url(admin_url('edit.php?post_type=download&page=edd-reports&view=downloads&download-id=' . $post_id)) . '">';
                    echo edd_currency_filter(edd_format_amount(edd_get_download_earnings_stats($post_id)));
                    echo '</a>';
                } else {
                    echo '-';
                }
                break;
        }
    }
}
Пример #14
0
 /**
  * Test that EDD sale of non-variable product is properly priced/recorded
  *
  * @since 1.1.0
  *
  * @group pricez
  * @group edd_price
  *
  * @covers \ingot\testing\tests\price\plugins\edd
  */
 public function testPriceTrackingNonVariableProduct()
 {
     $price_is = 10;
     $product = ingot_test_data_price::edd_create_simple_download($price_is);
     $group_id = \ingot\testing\crud\group::create(['type' => 'price', 'sub_type' => 'edd', 'meta' => ['product_ID' => $product->ID], 'wp_ID' => $product->ID], true);
     $variant_one = \ingot\testing\crud\variant::create(['group_ID' => $group_id, 'type' => 'price', 'meta' => ['price' => [0.5]], 'content' => $product->ID], true);
     $variant_two = \ingot\testing\crud\variant::create(['group_ID' => $group_id, 'type' => 'price', 'meta' => ['price' => [0.5]], 'content' => $product->ID], true);
     $group = \ingot\testing\crud\group::read($group_id);
     $group['variants'] = [$variant_one, $variant_two];
     \ingot\testing\crud\group::update($group, $group_id, true);
     $cookie_class = new \ingot\testing\cookies\price([]);
     $price_cookie = $cookie_class->get_cookie();
     $this->assertArrayHasKey('edd', $price_cookie);
     $this->assertFalse(empty($price_cookie['edd']));
     $this->assertInternalType('array', $price_cookie['edd']);
     $product_id = \ingot\testing\utility\price::get_product_ID($group);
     $this->assertEquals($product_id, $product->ID);
     $this->assertArrayHasKey($product_id, $price_cookie['edd']);
     new \ingot\testing\tests\price\plugins\edd($price_cookie['edd']);
     $test = \ingot\testing\utility\price::get_price_test_from_cookie('edd', $product->ID, $price_cookie);
     $this->assertInternalType('object', $test);
     $price_should_be = $test->get_price();
     //NOTE: USING edd_get_download_price here is to ensure we don't have recursion
     $this->assertEquals(edd_get_download_price($product->ID), $price_should_be);
     $group_obj = new \ingot\testing\object\group($group_id);
     $lever = $group_obj->get_lever($test->ID);
     $this->assertInternalType('object', $lever);
     $before_wins = $lever->getNumerator();
     $payment_id = ingot_test_data_price::edd_create_simple_payment($product);
     edd_complete_purchase($payment_id, 'publish', 'pending');
     $group_obj = new \ingot\testing\object\group($group_id);
     $lever = $group_obj->get_lever($test->ID);
     $this->assertInternalType('object', $lever);
     $after_wins = $lever->getNumerator();
     $this->assertEquals($before_wins + 1, $after_wins);
 }
/**
 * Maybe add incentive discounts
 *
 * @since		1.0.1
 * @param		float $discount The current discount amount
 * @param		array $item The cart item array
 * @return		float $discount The updated discount amount
 */
function edd_wallet_item_incentive_amount($discount, $item)
{
    $incentive_amount = edd_get_option('edd_wallet_incentive_amount', 0);
    if ($incentive_amount <= 0) {
        return $discount;
    }
    if (!EDD()->session->get('wallet_has_incentives')) {
        return $discount;
    }
    if (edd_has_variable_prices($item['id'])) {
        $prices = edd_get_variable_prices($item['id']);
        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : 0;
        if ($price_id !== false && $price_id !== '' && isset($prices[$price_id])) {
            $price = edd_get_price_option_amount($item['id'], $price_id);
        } else {
            $price = edd_get_lowest_price_option($item['id']);
        }
    } else {
        $price = edd_get_download_price($item['id']);
    }
    $incentive_type = edd_get_option('edd_wallet_incentive_type', 'flatrate');
    if ($incentive_type == 'percent') {
        $incentive_amount /= 100;
        $incentive_amount = $price * $incentive_amount;
        if (edd_item_quantities_enabled() && edd_get_option('edd_wallet_incentive_quantities', false)) {
            $incentive_amount *= $item['quantity'];
        }
        $incentive_amount = number_format($incentive_amount, 2, '.', '');
    } else {
        if (edd_item_quantities_enabled() && edd_get_option('edd_wallet_incentive_quantities', false)) {
            $incentive_amount *= $item['quantity'];
        }
    }
    $discount += $incentive_amount;
    return $discount;
}
 /**
  * Create sample purchase data for your EDD site
  *
  * ## OPTIONS
  *
  * --number: The number of purchases to create
  * --status=<status>: The status to create purchases as
  * --id=<product_id>: A specific product to create purchase data for
  * --price_id=<price_id>: A price ID of the specified product
  *
  * ## EXAMPLES
  *
  * wp edd payments create --number=10 --status=completed
  * wp edd payments create --number=10 --id=103
  */
 public function payments($args, $assoc_args)
 {
     $error = false;
     // At some point we'll likely add another action for payments
     if (!isset($args) || count($args) == 0) {
         $error = __('No action specified, did you mean', 'easy-digital-downloads');
     } elseif (isset($args) && !in_array('create', $args)) {
         $error = __('Invalid action specified, did you mean', 'easy-digital-downloads');
     }
     if ($error) {
         foreach ($assoc_args as $key => $value) {
             $query .= ' --' . $key . '=' . $value;
         }
         WP_CLI::error(sprintf($error . ' %s?', 'wp edd payments create' . $query));
         return;
     }
     // Setup some defaults
     $number = 1;
     $status = 'complete';
     $id = false;
     $price_id = false;
     if (count($assoc_args) > 0) {
         $number = array_key_exists('number', $assoc_args) ? absint($assoc_args['number']) : $number;
         $id = array_key_exists('id', $assoc_args) ? absint($assoc_args['id']) : $id;
         $price_id = array_key_exists('price_id', $assoc_args) ? absint($assoc_args['id']) : false;
         $tax = array_key_exists('tax', $assoc_args) ? floatval($assoc_args['tax']) : 0;
         $email = array_key_exists('email', $assoc_args) ? sanitize_email($assoc_args['email']) : '*****@*****.**';
         $fname = array_key_exists('fname', $assoc_args) ? sanitize_text_field($assoc_args['fname']) : 'Pippin';
         $lname = array_key_exists('lname', $assoc_args) ? sanitize_text_field($assoc_args['lname']) : 'Williamson';
         // Status requires a bit more validation
         if (array_key_exists('status', $assoc_args)) {
             $stati = array('publish', 'complete', 'pending', 'refunded', 'revoked', 'failed', 'abandoned', 'preapproval', 'cancelled');
             if (in_array($assoc_args['status'], $stati)) {
                 $status = $assoc_args['status'] == 'complete' ? 'publish' : $assoc_args['status'];
             } else {
                 WP_CLI::warning(sprintf(__("Invalid status '%s', defaulting to 'complete'", 'easy-digital-downloads'), $assoc_args['status']));
             }
         }
     }
     // Build the user info array
     $user_info = array('id' => 0, 'email' => $email, 'first_name' => $fname, 'last_name' => $lname, 'discount' => 'none');
     for ($i = 0; $i < $number; $i++) {
         $products = array();
         $total = 0;
         // No specified product
         if (!$id) {
             $products = get_posts(array('post_type' => 'download', 'orderby' => 'rand', 'order' => 'ASC', 'posts_per_page' => 1));
         } else {
             $product = get_post($id);
             if ($product->post_type != 'download') {
                 WP_CLI::error(__('Specified ID is not a product', 'easy-digital-downloads'));
                 return;
             }
             $products[] = $product;
         }
         $cart_details = array();
         // Create the purchases
         foreach ($products as $key => $download) {
             if (!is_a($download, 'WP_Post')) {
                 continue;
             }
             $options = array();
             $final_downloads = array();
             // Deal with variable pricing
             if (edd_has_variable_prices($download->ID)) {
                 $prices = edd_get_variable_prices($download->ID);
                 if (false === $price_id || !array_key_exists($price_id, (array) $prices)) {
                     $price_id = rand(0, count($prices) - 1);
                 }
                 $item_price = $prices[$price_id]['amount'];
                 $options['price_id'] = $price_id;
             } else {
                 $item_price = edd_get_download_price($download->ID);
             }
             $item_number = array('id' => $download->ID, 'quantity' => 1, 'options' => $options);
             $cart_details[$key] = array('name' => $download->post_title, 'id' => $download->ID, 'item_number' => $item_number, 'item_price' => edd_sanitize_amount($item_price), 'subtotal' => edd_sanitize_amount($item_price), 'price' => edd_sanitize_amount($item_price), 'quantity' => 1, 'discount' => 0, 'tax' => $tax);
             $final_downloads[$key] = $item_number;
             $total += $item_price;
         }
         $purchase_data = array('price' => edd_sanitize_amount($total), 'tax' => 0, 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $email, 'user_info' => $user_info, 'currency' => edd_get_currency(), 'downloads' => $final_downloads, 'cart_details' => $cart_details, 'status' => 'pending');
         $payment_id = edd_insert_payment($purchase_data);
         remove_action('edd_complete_purchase', 'edd_trigger_purchase_receipt', 999);
         if ($status != 'pending') {
             edd_update_payment_status($payment_id, $status);
         }
     }
     WP_CLI::success(sprintf(__('Created %s payments', 'easy-digital-downloads'), $number));
     return;
 }
Пример #17
0
function amt_product_data_jsonld_schemaorg_edd($metatags, $post)
{
    // Price
    $metatags['price'] = edd_get_download_price($post->ID);
    // Currency
    $metatags['priceCurrency'] = edd_get_currency();
    $metatags = apply_filters('amt_product_data_edd_jsonld_schemaorg', $metatags);
    return $metatags;
}
/**
 * Retrieves most expensive price option of a variable priced download
 *
 * @since 1.4.4
 * @param int $download_id ID of the download
 * @return float Amount of the highest price
 */
function edd_get_highest_price_option($download_id = 0)
{
    if (empty($download_id)) {
        $download_id = get_the_ID();
    }
    if (!edd_has_variable_prices($download_id)) {
        return edd_get_download_price($download_id);
    }
    $prices = edd_get_variable_prices($download_id);
    $high = 0.0;
    if (!empty($prices)) {
        $max = 0;
        foreach ($prices as $key => $price) {
            if (empty($price['amount'])) {
                continue;
            }
            $max = max($max, $price['amount']);
            if ($price['amount'] == $max) {
                $max_id = $key;
            }
        }
        $high = $prices[$max_id]['amount'];
    }
    return edd_sanitize_amount($high);
}
Пример #19
0
/**
 * Price Section
 *
 * If variable pricing is not enabled, simply output a single input box.
 *
 * If variable pricing is enabled, outputs a table of all current prices.
 * Extensions can add column heads to the table via the `edd_download_file_table_head`
 * hook, and actual columns via `edd_download_file_table_row`
 *
 * @since 1.0
 *
 * @see edd_render_price_row()
 *
 * @param $post_id
 */
function edd_render_price_field($post_id)
{
    $price = edd_get_download_price($post_id);
    $variable_pricing = edd_has_variable_prices($post_id);
    $prices = edd_get_variable_prices($post_id);
    $single_option_mode = edd_single_price_option_mode($post_id);
    $price_display = $variable_pricing ? ' style="display:none;"' : '';
    $variable_display = $variable_pricing ? '' : ' style="display:none;"';
    $currency_position = edd_get_option('currency_position', 'before');
    ?>
	<p>
		<strong><?php 
    echo apply_filters('edd_price_options_heading', __('Pricing Options:', 'edd'));
    ?>
</strong>
	</p>

	<p>
		<label for="edd_variable_pricing">
			<input type="checkbox" name="_variable_pricing" id="edd_variable_pricing" value="1" <?php 
    checked(1, $variable_pricing);
    ?>
 />
			<?php 
    echo apply_filters('edd_variable_pricing_toggle_text', __('Enable variable pricing', 'edd'));
    ?>
		</label>
	</p>

	<div id="edd_regular_price_field" class="edd_pricing_fields" <?php 
    echo $price_display;
    ?>
>
		<?php 
    $price_args = array('name' => 'edd_price', 'value' => isset($price) ? esc_attr(edd_format_amount($price)) : '', 'class' => 'edd-price-field');
    ?>

		<?php 
    if ($currency_position == 'before') {
        ?>
			<?php 
        echo edd_currency_filter('');
        ?>
			<?php 
        echo EDD()->html->text($price_args);
        ?>
		<?php 
    } else {
        ?>
			<?php 
        echo EDD()->html->text($price_args);
        ?>
			<?php 
        echo edd_currency_filter('');
        ?>
		<?php 
    }
    ?>

		<?php 
    do_action('edd_price_field', $post_id);
    ?>
	</div>

	<?php 
    do_action('edd_after_price_field', $post_id);
    ?>

	<div id="edd_variable_price_fields" class="edd_pricing_fields" <?php 
    echo $variable_display;
    ?>
>
		<input type="hidden" id="edd_variable_prices" class="edd_variable_prices_name_field" value=""/>
		<p>
			<?php 
    echo EDD()->html->checkbox(array('name' => '_edd_price_options_mode', 'current' => $single_option_mode));
    ?>
			<label for="_edd_price_options_mode"><?php 
    echo apply_filters('edd_multi_option_purchase_text', __('Enable multi-option purchase mode. Allows multiple price options to be added to your cart at once', 'edd'));
    ?>
</label>
		</p>
		<div id="edd_price_fields" class="edd_meta_table_wrap">
			<table class="widefat edd_repeatable_table" width="100%" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<th style="width: 20px"></th>
						<th><?php 
    _e('Option Name', 'edd');
    ?>
</th>
						<th style="width: 100px"><?php 
    _e('Price', 'edd');
    ?>
</th>
						<th class="edd_repeatable_default"><?php 
    _e('Default', 'edd');
    ?>
</th>
						<th style="width: 15px"><?php 
    _e('ID', 'edd');
    ?>
</th>
						<?php 
    do_action('edd_download_price_table_head', $post_id);
    ?>
						<th style="width: 2%"></th>
					</tr>
				</thead>
				<tbody>
					<?php 
    if (!empty($prices)) {
        foreach ($prices as $key => $value) {
            $name = isset($value['name']) ? $value['name'] : '';
            $amount = isset($value['amount']) ? $value['amount'] : '';
            $index = isset($value['index']) ? $value['index'] : $key;
            $args = apply_filters('edd_price_row_args', compact('name', 'amount'), $value);
            ?>
								<tr class="edd_variable_prices_wrapper edd_repeatable_row" data-key="<?php 
            echo esc_attr($key);
            ?>
">
									<?php 
            do_action('edd_render_price_row', $key, $args, $post_id, $index);
            ?>
								</tr>
							<?php 
        }
    } else {
        ?>
						<tr class="edd_variable_prices_wrapper edd_repeatable_row" data-key="1">
							<?php 
        do_action('edd_render_price_row', 1, array(), $post_id, 1);
        ?>
						</tr>
					<?php 
    }
    ?>

					<tr>
						<td class="submit" colspan="4" style="float: none; clear:both; background:#fff;">
							<a class="button-secondary edd_add_repeatable" style="margin: 6px 0;"><?php 
    _e('Add New Price', 'edd');
    ?>
</a>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div><!--end #edd_variable_price_fields-->
<?php 
}
/**
 * Generate PDF Reports
 *
 * Generates PDF report on sales and earnings for all downloads for the current year.
 *
 * @since 1.1.4.0
 * @param string $data
 * @uses edd_pdf
 * @author Sunny Ratilal
 */
function edd_generate_pdf($data)
{
    $edd_pdf_reports_nonce = $_GET['_wpnonce'];
    if (wp_verify_nonce($edd_pdf_reports_nonce, 'edd_generate_pdf')) {
        require_once EDD_PLUGIN_DIR . '/includes/libraries/fpdf/fpdf.php';
        require_once EDD_PLUGIN_DIR . '/includes/libraries/fpdf/edd_pdf.php';
        $daterange = date_i18n(get_option('date_format'), mktime(0, 0, 0, 1, 1, date('Y'))) . ' ' . utf8_decode(__('to', 'edd')) . ' ' . date_i18n(get_option('date_format'));
        $pdf = new edd_pdf();
        $pdf->AddPage('L', 'A4');
        $pdf->SetTitle(utf8_decode(__('Sales and earnings reports for the current year for all products', 'edd')));
        $pdf->SetAuthor(utf8_decode(__('Easy Digital Downloads', 'edd')));
        $pdf->SetCreator(utf8_decode(__('Easy Digital Downloads', 'edd')));
        $pdf->Image(EDD_PLUGIN_URL . 'assets/images/edd-logo.png', 205, 10);
        $pdf->SetMargins(8, 8, 8);
        $pdf->SetX(8);
        $pdf->SetFont('Helvetica', '', 16);
        $pdf->SetTextColor(50, 50, 50);
        $pdf->Cell(0, 3, utf8_decode(__('Sales and earnings reports for the current year for all products', 'edd')), 0, 2, 'L', false);
        $pdf->SetFont('Helvetica', '', 13);
        $pdf->Ln();
        $pdf->SetTextColor(150, 150, 150);
        $pdf->Cell(0, 6, utf8_decode(__('Date Range: ', 'edd')) . $daterange, 0, 2, 'L', false);
        $pdf->Ln();
        $pdf->SetTextColor(50, 50, 50);
        $pdf->SetFont('Helvetica', '', 14);
        $pdf->Cell(0, 10, utf8_decode(__('Table View', 'edd')), 0, 2, 'L', false);
        $pdf->SetFont('Helvetica', '', 12);
        $pdf->SetFillColor(238, 238, 238);
        $pdf->Cell(70, 6, utf8_decode(__('Product Name', 'edd')), 1, 0, 'L', true);
        $pdf->Cell(30, 6, utf8_decode(__('Price', 'edd')), 1, 0, 'L', true);
        $pdf->Cell(50, 6, utf8_decode(__('Categories', 'edd')), 1, 0, 'L', true);
        $pdf->Cell(50, 6, utf8_decode(__('Tags', 'edd')), 1, 0, 'L', true);
        $pdf->Cell(45, 6, utf8_decode(__('Number of Sales', 'edd')), 1, 0, 'L', true);
        $pdf->Cell(35, 6, utf8_decode(__('Earnings to Date', 'edd')), 1, 1, 'L', true);
        $year = date('Y');
        $downloads = get_posts(array('post_type' => 'download', 'year' => $year, 'posts_per_page' => -1));
        if ($downloads) {
            $pdf->SetWidths(array(70, 30, 50, 50, 45, 35));
            foreach ($downloads as $download) {
                $pdf->SetFillColor(255, 255, 255);
                $title = utf8_decode(get_the_title($download->ID));
                if (edd_has_variable_prices($download->ID)) {
                    $prices = edd_get_variable_prices($download->ID);
                    $first = $prices[0]['amount'];
                    $last = array_pop($prices);
                    $last = $last['amount'];
                    if ($first < $last) {
                        $min = $first;
                        $max = $last;
                    } else {
                        $min = $last;
                        $max = $first;
                    }
                    $price = html_entity_decode(edd_currency_filter(edd_format_amount($min)) . ' - ' . edd_currency_filter(edd_format_amount($max)));
                } else {
                    $price = html_entity_decode(edd_currency_filter(edd_get_download_price($download->ID)));
                }
                $categories = get_the_term_list($download->ID, 'download_category', '', ', ', '');
                $categories = $categories ? strip_tags($categories) : '';
                $tags = get_the_term_list($download->ID, 'download_tag', '', ', ', '');
                $tags = $tags ? strip_tags($tags) : '';
                $sales = edd_get_download_sales_stats($download->ID);
                $link = get_permalink($download->ID);
                $earnings = html_entity_decode(edd_currency_filter(edd_get_download_earnings_stats($download->ID)));
                $pdf->Row(array($title, $price, $categories, $tags, $sales, $earnings));
            }
        } else {
            $pdf->SetWidths(array(280));
            $title = utf8_decode(sprintf(__('No %s found.', 'edd'), edd_get_label_plural()));
            $pdf->Row(array($title));
        }
        $pdf->Ln();
        $pdf->SetTextColor(50, 50, 50);
        $pdf->SetFont('Helvetica', '', 14);
        $pdf->Cell(0, 10, utf8_decode(__('Graph View', 'edd')), 0, 2, 'L', false);
        $pdf->SetFont('Helvetica', '', 12);
        $image = html_entity_decode(urldecode(edd_draw_chart_image()));
        $image = str_replace(' ', '%20', $image);
        $pdf->SetX(25);
        $pdf->Image($image . '&file=.png');
        $pdf->Ln(7);
        $pdf->Output('edd-report-' . date_i18n('Y-m-d') . '.pdf', 'D');
    }
}
/**
 * Price
 *
 * Displays a formatted price for a download.
 *
 * @access      public
 * @since       1.0
 * @param       int $download_id the ID of the download price to show
 * @param		bool whether to echo or return the results
* @return       void
*/
function edd_price($download_id, $echo = true)
{
    if (edd_has_variable_prices($download_id)) {
        $prices = edd_get_variable_prices($download_id);
        $price = $prices[0]['amount'];
        // show the first price option
    } else {
        $price = edd_get_download_price($download_id);
    }
    $price = apply_filters('edd_download_price', $price, $download_id);
    if ($echo) {
        echo $price;
    } else {
        return $price;
    }
}
Пример #22
0
/**
 * Retrieve the cost to upgrade a license
 *
 * @since 3.3
 * @return float
 */
function edd_sl_get_license_upgrade_cost($license_id = 0, $upgrade_id = 0)
{
    $url = home_url();
    $download_id = edd_software_licensing()->get_download_id($license_id);
    $upgrades = edd_sl_get_upgrade_paths($download_id);
    if (edd_has_variable_prices($download_id)) {
        $price_id = edd_software_licensing()->get_price_id($license_id);
        if (false !== $price_id && '' !== $price_id) {
            $old_price = edd_get_price_option_amount($download_id, $price_id);
        } else {
            $old_price = edd_get_lowest_price_option($download_id);
        }
    } else {
        $old_price = edd_get_download_price($download_id);
    }
    if (isset($upgrades[$upgrade_id]['price_id']) && false !== $upgrades[$upgrade_id]['price_id']) {
        $new_price = edd_get_price_option_amount($upgrades[$upgrade_id]['download_id'], $upgrades[$upgrade_id]['price_id']);
    } else {
        $new_price = edd_get_download_price($upgrades[$upgrade_id]['download_id']);
    }
    $cost = $new_price;
    if (!empty($upgrades[$upgrade_id]['pro_rated'])) {
        $cost -= $old_price;
    }
    if (isset($upgrades[$upgrade_id]['discount'])) {
        $cost -= $upgrades[$upgrade_id]['discount'];
    }
    if ($cost < 0) {
        $cost = 0;
    }
    return apply_filters('edd_sl_license_upgrade_cost', $cost, $license_id, $upgrade_id);
}
 /**
  * Given a download post object, generate the data for the API output
  *
  * @since  2.3.9
  * @param  object $product_info The Download Post Object
  * @return array                Array of post data to return back in the API
  */
 private function get_product_data($product_info)
 {
     $product = array();
     $product['info']['id'] = $product_info->ID;
     $product['info']['slug'] = $product_info->post_name;
     $product['info']['title'] = $product_info->post_title;
     $product['info']['create_date'] = $product_info->post_date;
     $product['info']['modified_date'] = $product_info->post_modified;
     $product['info']['status'] = $product_info->post_status;
     $product['info']['link'] = html_entity_decode($product_info->guid);
     $product['info']['content'] = $product_info->post_content;
     $product['info']['excerpt'] = $product_info->post_excerpt;
     $product['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($product_info->ID));
     $product['info']['category'] = get_the_terms($product_info, 'download_category');
     $product['info']['tags'] = get_the_terms($product_info, 'download_tag');
     if (user_can($this->user_id, 'view_shop_reports') || $this->override) {
         $product['stats']['total']['sales'] = edd_get_download_sales_stats($product_info->ID);
         $product['stats']['total']['earnings'] = edd_get_download_earnings_stats($product_info->ID);
         $product['stats']['monthly_average']['sales'] = edd_get_average_monthly_download_sales($product_info->ID);
         $product['stats']['monthly_average']['earnings'] = edd_get_average_monthly_download_earnings($product_info->ID);
     }
     if (edd_has_variable_prices($product_info->ID)) {
         foreach (edd_get_variable_prices($product_info->ID) as $price) {
             $product['pricing'][sanitize_key($price['name'])] = $price['amount'];
         }
     } else {
         $product['pricing']['amount'] = edd_get_download_price($product_info->ID);
     }
     if (user_can($this->user_id, 'view_shop_sensitive_data') || $this->override) {
         foreach (edd_get_download_files($product_info->ID) as $file) {
             $product['files'][] = $file;
         }
         $product['notes'] = edd_get_product_notes($product_info->ID);
     }
     return apply_filters('edd_api_products_product', $product);
 }
function amt_product_data_schemaorg_edd($metatags, $post)
{
    // Price
    $metatags[] = '<meta itemprop="price" content="' . edd_get_download_price($post->ID) . '" />';
    // Currency
    $metatags[] = '<meta itemprop="priceCurrency" content="' . edd_get_currency() . '" />';
    $metatags = apply_filters('amt_product_data_edd_schemaorg', $metatags);
    return $metatags;
}
 /**
  * Widget
  *
  * @return   void
  * @since    1.0
  */
 function widget($args, $instance)
 {
     // get the title and apply filters
     $title = apply_filters('widget_title', $instance['title'] ? $instance['title'] : '');
     // get show price boolean
     $show_price = isset($instance['show_price']) && $instance['show_price'] === 1 ? 1 : 0;
     // get the thumbnail boolean
     $thumbnail = isset($instance['thumbnail']) && $instance['thumbnail'] === 1 ? 1 : 0;
     // set the thumbnail size
     $thumbnail_size = isset($instance['thumbnail_size']) ? $instance['thumbnail_size'] : 80;
     // start collecting the output
     $out = "";
     // check if there is a title
     if ($title) {
         // add the title to the ouput
         $out .= $args['before_title'] . $title . $args['after_title'];
     }
     // set the params
     $params = array('post_type' => 'download', 'posts_per_page' => 1, 'post_status' => 'publish', 'orderby' => 'rand');
     // get the random download
     $random_download = get_posts($params);
     // check download
     if (is_null($random_download) || empty($random_download)) {
         // return if there is no download
         return;
     } else {
         // start the list output
         $out .= "<ul class=\"widget-random-download\">\n";
         // set the link structure
         $link = "<a href=\"%s\" title=\"%s\" class=\"%s\" rel=\"bookmark\">%s</a>\n";
         // filter the thumbnail size
         $thumbnail_size = apply_filters('edd_widgets_random_download_thumbnail_size', array($thumbnail_size, $thumbnail_size));
         // loop trough the random download
         foreach ($random_download as $download) {
             // get the title
             $title = apply_filters('the_title', $download->post_title, $download->ID);
             $title_attr = apply_filters('the_title_attribute', $download->post_title, $download->ID);
             // get the post thumbnail
             if ($thumbnail === 1 && function_exists('has_post_thumbnail') && has_post_thumbnail($download->ID)) {
                 $post_thumbnail = get_the_post_thumbnail($download->ID, $thumbnail_size, array('title' => esc_attr($title_attr))) . "\n";
                 $out .= "<li class=\"widget-download-with-thumbnail\">\n";
                 $out .= sprintf($link, get_permalink($download->ID), esc_attr($title_attr), 'widget-download-thumb', $post_thumbnail);
             } else {
                 $out .= "<li>\n";
             }
             // append the download's title
             $out .= sprintf($link, get_permalink($download->ID), esc_attr($title_attr), 'widget-download-title', $title);
             // get the price
             if ($show_price === 1) {
                 if (edd_has_variable_prices($download->ID)) {
                     $price = edd_price_range($download->ID);
                 } else {
                     $price = edd_currency_filter(edd_get_download_price($download->ID));
                 }
                 $out .= sprintf("<span class=\"widget-download-price\">%s</span>\n", $price);
             }
             // finish this element
             $out .= "</li>\n";
         }
         // finish the list
         $out .= "</ul>\n";
     }
     // set the widget's containers
     echo $args['before_widget'] . $out . $args['after_widget'];
 }
 /**
  * Add a download to a given payment
  *
  * @since 2.5
  * @param int  $download_id The download to add
  * @param int  $args Other arguments to pass to the function
  * @return void
  */
 public function add_download($download_id = 0, $args = array(), $options = array())
 {
     $download = new EDD_Download($download_id);
     // Bail if this post isn't a download
     if (!$download || $download->post_type !== 'download') {
         return false;
     }
     // Set some defaults
     $defaults = array('quantity' => 1, 'price_id' => false, 'item_price' => 0.0, 'discount' => 0, 'tax' => 0.0, 'fees' => array());
     $args = wp_parse_args(apply_filters('edd_payment_add_download_args', $args, $download->ID), $defaults);
     // Allow overriding the price
     if ($args['item_price']) {
         $item_price = $args['item_price'];
     } else {
         // Deal with variable pricing
         if (edd_has_variable_prices($download->ID)) {
             $prices = get_post_meta($download->ID, 'edd_variable_prices', true);
             if ($args['price_id'] && array_key_exists($args['price_id'], (array) $prices)) {
                 $item_price = $prices[$args['price_id']]['amount'];
             } else {
                 $item_price = edd_get_lowest_price_option($download->ID);
                 $args['price_id'] = edd_get_lowest_price_id($download->ID);
             }
         } else {
             $item_price = edd_get_download_price($download->ID);
         }
     }
     // Sanitizing the price here so we don't have a dozen calls later
     $item_price = edd_sanitize_amount($item_price);
     $quantity = edd_item_quantities_enabled() ? absint($args['quantity']) : 1;
     $amount = round($item_price * $quantity, edd_currency_decimal_filter());
     if (!empty($args['fees'])) {
         foreach ($args['fees'] as $key => $fee) {
             if (empty($fee['download_id'])) {
                 $args['fees'][$key]['download_id'] = $download_id;
             }
             $this->add_fee($args['fees'][$key], false);
         }
     }
     // Setup the downloads meta item
     $new_download = array('id' => $download->ID, 'quantity' => $quantity, 'fees' => $args['fees']);
     $default_options = array('quantity' => $quantity);
     if (!empty($args['price_id'])) {
         $default_options['price_id'] = (int) $args['price_id'];
     }
     $options = wp_parse_args($options, $default_options);
     $new_download['options'] = $options;
     $this->downloads[] = $new_download;
     $discount = $args['discount'];
     $subtotal = $amount;
     $tax = $args['tax'];
     if (edd_prices_include_tax()) {
         $subtotal -= round($tax, edd_currency_decimal_filter());
     }
     $total = $subtotal - $discount + $tax;
     // Do not allow totals to go negatve
     if ($total < 0) {
         $total = 0;
     }
     // Silly item_number array
     $item_number = array('id' => $download->ID, 'quantity' => $quantity, 'options' => $options);
     $this->cart_details[] = array('name' => $download->post_title, 'id' => $download->ID, 'item_number' => $item_number, 'item_price' => round($item_price, edd_currency_decimal_filter()), 'quantity' => $quantity, 'discount' => $discount, 'subtotal' => round($subtotal, edd_currency_decimal_filter()), 'tax' => round($tax, edd_currency_decimal_filter()), 'fees' => $args['fees'], 'price' => round($total, edd_currency_decimal_filter()));
     $added_download = end($this->cart_details);
     $added_download['action'] = 'add';
     $this->pending['downloads'][] = $added_download;
     reset($this->cart_details);
     $this->increase_subtotal($subtotal - $discount);
     $this->increase_tax($tax);
     return true;
 }
/**
 * Get Cart Item Price
 *
 * Gets the price of the cart item. Always exclusive of taxes
 *
 * Do not use this for getting the final price (with taxes and discounts) of an item.
 * Use edd_get_cart_item_final_price()
 *
 * @since 1.0
 * @param int   $download_id Download ID number
 * @param array $options Optional parameters, used for defining variable prices
 * @return float|bool Price for this item
 */
function edd_get_cart_item_price($download_id = 0, $options = array())
{
    $price = 0;
    $variable_prices = edd_has_variable_prices($download_id);
    if ($variable_prices) {
        $prices = edd_get_variable_prices($download_id);
        if ($prices) {
            if (!empty($options)) {
                $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
            } else {
                $price = false;
            }
        }
    }
    if (!$variable_prices || false === $price) {
        // Get the standard Download price if not using variable prices
        $price = edd_get_download_price($download_id);
    }
    return apply_filters('edd_cart_item_price', $price, $download_id, $options);
}
 /**
  * Process Get Products API Request
  *
  * @access public
  * @author Daniel J Griffiths
  * @since 1.5
  * @param int $product Product (Download) ID
  * @return array $customers Multidimensional array of the products
  */
 public function get_products($product = null)
 {
     $products = array();
     if ($product == null) {
         $products['products'] = array();
         $product_list = get_posts(array('post_type' => 'download', 'posts_per_page' => $this->per_page(), 'paged' => $this->get_paged()));
         if ($product_list) {
             $i = 0;
             foreach ($product_list as $product_info) {
                 $products['products'][$i]['info']['id'] = $product_info->ID;
                 $products['products'][$i]['info']['slug'] = $product_info->post_name;
                 $products['products'][$i]['info']['title'] = $product_info->post_title;
                 $products['products'][$i]['info']['create_date'] = $product_info->post_date;
                 $products['products'][$i]['info']['modified_date'] = $product_info->post_modified;
                 $products['products'][$i]['info']['status'] = $product_info->post_status;
                 $products['products'][$i]['info']['link'] = html_entity_decode($product_info->guid);
                 $products['products'][$i]['info']['content'] = $product_info->post_content;
                 $products['products'][$i]['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($product_info->ID));
                 $products['products'][$i]['stats']['total']['sales'] = edd_get_download_sales_stats($product_info->ID);
                 $products['products'][$i]['stats']['total']['earnings'] = edd_get_download_earnings_stats($product_info->ID);
                 $products['products'][$i]['stats']['monthly_average']['sales'] = edd_get_average_monthly_download_sales($product_info->ID);
                 $products['products'][$i]['stats']['monthly_average']['earnings'] = edd_get_average_monthly_download_earnings($product_info->ID);
                 if (edd_has_variable_prices($product_info->ID)) {
                     foreach (edd_get_variable_prices($product_info->ID) as $price) {
                         $products['products'][$i]['pricing'][sanitize_key($price['name'])] = $price['amount'];
                     }
                 } else {
                     $products['products'][$i]['pricing']['amount'] = edd_get_download_price($product_info->ID);
                 }
                 foreach (edd_get_download_files($product_info->ID) as $file) {
                     $products['products'][$i]['files'][] = $file;
                 }
                 $products['products'][$i]['notes'] = edd_get_product_notes($product_info->ID);
                 $i++;
             }
         }
     } else {
         if (get_post_type($product) == 'download') {
             $product_info = get_post($product);
             $products['products'][0]['info']['id'] = $product_info->ID;
             $products['products'][0]['info']['slug'] = $product_info->post_name;
             $products['products'][0]['info']['title'] = $product_info->post_title;
             $products['products'][0]['info']['create_date'] = $product_info->post_date;
             $products['products'][0]['info']['modified_date'] = $product_info->post_modified;
             $products['products'][0]['info']['status'] = $product_info->post_status;
             $products['products'][0]['info']['link'] = html_entity_decode($product_info->guid);
             $products['products'][0]['info']['content'] = $product_info->post_content;
             $products['products'][0]['info']['thumbnail'] = wp_get_attachment_url(get_post_thumbnail_id($product_info->ID));
             $products['products'][0]['stats']['total']['sales'] = edd_get_download_sales_stats($product_info->ID);
             $products['products'][0]['stats']['total']['earnings'] = edd_get_download_earnings_stats($product_info->ID);
             $products['products'][0]['stats']['monthly_average']['sales'] = edd_get_average_monthly_download_sales($product_info->ID);
             $products['products'][0]['stats']['monthly_average']['earnings'] = edd_get_average_monthly_download_earnings($product_info->ID);
             if (edd_has_variable_prices($product_info->ID)) {
                 foreach (edd_get_variable_prices($product_info->ID) as $price) {
                     $products['products'][0]['pricing'][sanitize_key($price['name'])] = $price['amount'];
                 }
             } else {
                 $products['products'][0]['pricing']['amount'] = edd_get_download_price($product_info->ID);
             }
             foreach (edd_get_download_files($product_info->ID) as $file) {
                 $products['products'][0]['files'][] = $file;
             }
             $products['products'][0]['notes'] = edd_get_product_notes($product_info->ID);
         } else {
             $error['error'] = sprintf(__('Product %s not found!', 'edd'), $product);
             return $error;
         }
     }
     return $products;
 }
 /**
  * Get Downloads Earning Points 
  * 
  * Handles to return earning points for download
  * 
  * @package Easy Digital Downloads - Points and Rewards
  * @since 1.0.0
  **/
 public function edd_points_get_earning_points($downloadid, $priceoptions = array(), $checkout = false)
 {
     //if this function called from checkout page then use third parameter to TRUE
     global $edd_options;
     $earningpointsbyuser = 0;
     //check if price is for checkout page
     if (!empty($checkout)) {
         //if checkout page
         $edd_price = edd_get_cart_item_price($downloadid, $priceoptions);
     } else {
         //if not is checkout page
         if (edd_has_variable_prices($downloadid)) {
             //check product price is varible pricing enable or not
             //$prices = edd_get_variable_prices( $downloadid );
             //$edd_price = edd_sanitize_amount( $prices[0]['amount'] );
             $edd_price[0] = edd_get_lowest_price_option($downloadid);
             $edd_price[1] = edd_get_highest_price_option($downloadid);
         } else {
             //get download price
             $edd_price = edd_get_download_price($downloadid);
         }
         //end else
     }
     //end else
     //get download points for download level from meta box
     $downloadearnpoints = $this->edd_points_get_download_earn_points($downloadid);
     if (is_numeric($downloadearnpoints)) {
         return $downloadearnpoints;
     }
     //check if points of download are set in category level
     $downloadearnpoints = $this->edd_points_get_category_earn_points($downloadid);
     if (is_numeric($downloadearnpoints)) {
         return $downloadearnpoints;
     }
     if (is_array($edd_price)) {
         // if product is variable then edd_price contains array of lowest and highest price
         $earning_points_by_user = array();
         foreach ($edd_price as $key => $data) {
             $earning_points_by_user[$key] = $this->edd_points_calculate_earn_points_from_price($data);
         }
         return $earning_points_by_user;
     } else {
         // if product is simple product
         //calculate the earn points from price
         $earningpointsbyuser = $this->edd_points_calculate_earn_points_from_price($edd_price);
     }
     // get download points based on global setting
     return $earningpointsbyuser;
 }
Пример #30
0
/**
 * Generate PDF Reports
 *
 * Generates PDF report on sales and earnings for all downloads for the current year.
 *
 * @since 1.1.4.0
 * @param string $data
 * @uses edd_pdf
 * @author Sunny Ratilal
 */
function edd_generate_pdf($data)
{
    if (!current_user_can('view_shop_reports')) {
        wp_die(__('You do not have permission to generate PDF sales reports', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403));
    }
    if (!wp_verify_nonce($_GET['_wpnonce'], 'edd_generate_pdf')) {
        wp_die(__('Nonce verification failed', 'easy-digital-downloads'), __('Error', 'easy-digital-downloads'), array('response' => 403));
    }
    require_once EDD_PLUGIN_DIR . '/includes/libraries/fpdf/fpdf.php';
    require_once EDD_PLUGIN_DIR . '/includes/libraries/fpdf/edd_pdf.php';
    $daterange = date_i18n(get_option('date_format'), mktime(0, 0, 0, 1, 1, date('Y'))) . ' ' . utf8_decode(__('to', 'easy-digital-downloads')) . ' ' . date_i18n(get_option('date_format'));
    $pdf = new edd_pdf();
    $pdf->AddPage('L', 'A4');
    $pdf->SetTitle(utf8_decode(__('Sales and earnings reports for the current year for all products', 'easy-digital-downloads')));
    $pdf->SetAuthor(utf8_decode(__('Easy Digital Downloads', 'easy-digital-downloads')));
    $pdf->SetCreator(utf8_decode(__('Easy Digital Downloads', 'easy-digital-downloads')));
    $pdf->Image(EDD_PLUGIN_URL . 'assets/images/edd-logo-pdf.png', 205, 10);
    $pdf->SetMargins(8, 8, 8);
    $pdf->SetX(8);
    $pdf->SetFont('Helvetica', '', 16);
    $pdf->SetTextColor(50, 50, 50);
    $pdf->Cell(0, 3, utf8_decode(__('Sales and earnings reports for the current year for all products', 'easy-digital-downloads')), 0, 2, 'L', false);
    $pdf->SetFont('Helvetica', '', 13);
    $pdf->Ln();
    $pdf->SetTextColor(150, 150, 150);
    $pdf->Cell(0, 6, utf8_decode(__('Date Range: ', 'easy-digital-downloads')) . $daterange, 0, 2, 'L', false);
    $pdf->Ln();
    $pdf->SetTextColor(50, 50, 50);
    $pdf->SetFont('Helvetica', '', 14);
    $pdf->Cell(0, 10, utf8_decode(__('Table View', 'easy-digital-downloads')), 0, 2, 'L', false);
    $pdf->SetFont('Helvetica', '', 12);
    $pdf->SetFillColor(238, 238, 238);
    $pdf->Cell(70, 6, utf8_decode(__('Product Name', 'easy-digital-downloads')), 1, 0, 'L', true);
    $pdf->Cell(30, 6, utf8_decode(__('Price', 'easy-digital-downloads')), 1, 0, 'L', true);
    $category_labels = edd_get_taxonomy_labels('download_category');
    $pdf->Cell(50, 6, utf8_decode($category_labels['name']), 1, 0, 'L', true);
    $pdf->Cell(50, 6, utf8_decode(__('Tags', 'easy-digital-downloads')), 1, 0, 'L', true);
    $pdf->Cell(45, 6, utf8_decode(__('Number of Sales', 'easy-digital-downloads')), 1, 0, 'L', true);
    $pdf->Cell(35, 6, utf8_decode(__('Earnings to Date', 'easy-digital-downloads')), 1, 1, 'L', true);
    $year = date('Y');
    $downloads = get_posts(array('post_type' => 'download', 'year' => $year, 'posts_per_page' => -1));
    if ($downloads) {
        $pdf->SetWidths(array(70, 30, 50, 50, 45, 35));
        foreach ($downloads as $download) {
            $pdf->SetFillColor(255, 255, 255);
            $title = utf8_decode(get_the_title($download->ID));
            if (edd_has_variable_prices($download->ID)) {
                $prices = edd_get_variable_prices($download->ID);
                $first = $prices[0]['amount'];
                $last = array_pop($prices);
                $last = $last['amount'];
                if ($first < $last) {
                    $min = $first;
                    $max = $last;
                } else {
                    $min = $last;
                    $max = $first;
                }
                $price = html_entity_decode(edd_currency_filter(edd_format_amount($min)) . ' - ' . edd_currency_filter(edd_format_amount($max)));
            } else {
                $price = html_entity_decode(edd_currency_filter(edd_get_download_price($download->ID)));
            }
            $categories = get_the_term_list($download->ID, 'download_category', '', ', ', '');
            $categories = $categories ? strip_tags($categories) : '';
            $tags = get_the_term_list($download->ID, 'download_tag', '', ', ', '');
            $tags = $tags ? strip_tags($tags) : '';
            $sales = edd_get_download_sales_stats($download->ID);
            $earnings = html_entity_decode(edd_currency_filter(edd_get_download_earnings_stats($download->ID)));
            if (function_exists('iconv')) {
                // Ensure characters like euro; are properly converted. See GithuB issue #472 and #1570
                $price = iconv('UTF-8', 'windows-1252', utf8_encode($price));
                $earnings = iconv('UTF-8', 'windows-1252', utf8_encode($earnings));
            }
            $pdf->Row(array($title, $price, $categories, $tags, $sales, $earnings));
        }
    } else {
        $pdf->SetWidths(array(280));
        $title = utf8_decode(sprintf(__('No %s found.', 'easy-digital-downloads'), edd_get_label_plural()));
        $pdf->Row(array($title));
    }
    $pdf->Ln();
    $pdf->SetTextColor(50, 50, 50);
    $pdf->SetFont('Helvetica', '', 14);
    $pdf->Cell(0, 10, utf8_decode(__('Graph View', 'easy-digital-downloads')), 0, 2, 'L', false);
    $pdf->SetFont('Helvetica', '', 12);
    $image = html_entity_decode(urldecode(edd_draw_chart_image()));
    $image = str_replace(' ', '%20', $image);
    $pdf->SetX(25);
    $pdf->Image($image . '&file=.png');
    $pdf->Ln(7);
    $pdf->Output(apply_filters('edd_sales_earnings_pdf_export_filename', 'edd-report-' . date_i18n('Y-m-d')) . '.pdf', 'D');
}