/**
 * 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;
}
		<?php 
    }
    ?>
		<?php 
    if ($fees = edd_get_payment_fees($payment->ID, 'item')) {
        ?>
			<?php 
        foreach ($fees as $fee) {
            ?>
				<tr>
					<td class="edd_fee_label"><?php 
            echo esc_html($fee['label']);
            ?>
</td>
					<?php 
            if (edd_item_quantities_enabled()) {
                ?>
						<td></td>
					<?php 
            }
            ?>
					<td class="edd_fee_amount"><?php 
            echo edd_currency_filter(edd_format_amount($fee['amount']));
            ?>
</td>
				</tr>
			<?php 
        }
        ?>
		<?php 
    }
/**
 * Get Cart Item Quantity
 *
 * @since 1.0
 * @param int $download_id Download (cart item) ID number
 * @param array $options Download options, such as price ID
 * @return int $quantity Cart item quantity
 */
function edd_get_cart_item_quantity($download_id = 0, $options = array())
{
    $cart = edd_get_cart_contents();
    $key = edd_get_item_position_in_cart($download_id, $options);
    $quantity = isset($cart[$key]['quantity']) && edd_item_quantities_enabled() ? $cart[$key]['quantity'] : 1;
    if ($quantity < 1) {
        $quantity = 1;
    }
    return apply_filters('edd_get_cart_item_quantity', $quantity, $download_id, $options);
}
/**
 * Display the quantity field for a variable price when multi-purchase mode is enabled
 *
 * @since 2.2
 * @param int $key Price ID
 * @param array $price price option array
 * @param int $download_id Download ID
 * @return void
 */
function edd_variable_price_quantity_field($key, $price, $download_id)
{
    if (!edd_item_quantities_enabled()) {
        return;
    }
    if (!edd_single_price_option_mode($download_id)) {
        return;
    }
    ob_start();
    ?>
	<div class="edd_download_quantity_wrapper edd_download_quantity_price_option_<?php 
    echo sanitize_key($price['name']);
    ?>
">
		<span class="edd_price_option_sep">&nbsp;x&nbsp;</span>
		<input type="number" min="1" step="1" name="edd_download_quantity_<?php 
    echo esc_attr($key);
    ?>
" class="edd-input edd-item-quantity" value="1" />
	</div>
<?php 
    $quantity_input = ob_get_clean();
    echo apply_filters('edd_purchase_form_variation_quantity_input', $quantity_input, $download_id, $key, $price);
}
							$item_title = get_the_title( $item['id'] );
							if ( ! empty( $item['options'] ) && edd_has_variable_prices( $item['id'] ) ) {
								$item_title .= ' - ' . edd_get_cart_item_price_name( $item );
							}
							echo '<span class="edd_checkout_cart_item_title">' . esc_html( $item_title ) . '</span>';
							do_action( 'edd_checkout_cart_item_title_after', $item );
						?>
					</td>
					<td class="edd_cart_item_price">
						<?php 
						echo edd_cart_item_price( $item['id'], $item['options'] );
						do_action( 'edd_checkout_cart_item_price_after', $item );
						?>
					</td>
					<td class="edd_cart_actions">
						<?php if( edd_item_quantities_enabled() ) : ?>
							<input type="number" min="1" step="1" name="edd-cart-download-<?php echo $key; ?>-quantity" data-key="<?php echo $key; ?>" class="edd-input edd-item-quantity" value="<?php echo edd_get_cart_item_quantity( $item['id'], $item['options'] ); ?>"/>
							<input type="hidden" name="edd-cart-downloads[]" value="<?php echo $item['id']; ?>"/>
							<input type="hidden" name="edd-cart-download-<?php echo $key; ?>-options" value="<?php echo esc_attr( serialize( $item['options'] ) ); ?>"/>
						<?php endif; ?>
						<?php do_action( 'edd_cart_actions', $item, $key ); ?>
						<a class="edd_cart_remove_item_btn" href="<?php echo esc_url( edd_remove_item_url( $key ) ); ?>"><?php _e( 'Remove', 'edd' ); ?></a>
					</td>
					<?php do_action( 'edd_checkout_table_body_last', $item ); ?>
				</tr>
			<?php endforeach; ?>
		<?php endif; ?>
		<?php do_action( 'edd_cart_items_middle' ); ?>
		<!-- Show any cart fees, both positive and negative fees -->
		<?php if( edd_cart_has_fees() ) : ?>
			<?php foreach( edd_get_cart_fees() as $fee_id => $fee ) : ?>
Beispiel #6
0
/**
 * Load Admin Scripts
 *
 * Enqueues the required admin scripts.
 *
 * @since 1.0
 * @global $post
 * @param string $hook Page hook
 * @return void
 */
function edd_load_admin_scripts($hook)
{
    if (!apply_filters('edd_load_admin_scripts', edd_is_admin_page(), $hook)) {
        return;
    }
    global $wp_version, $post;
    $js_dir = EDD_PLUGIN_URL . 'assets/js/';
    $css_dir = EDD_PLUGIN_URL . 'assets/css/';
    // Use minified libraries if SCRIPT_DEBUG is turned off
    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
    // These have to be global
    wp_register_style('jquery-chosen', $css_dir . 'chosen' . $suffix . '.css', array(), EDD_VERSION);
    wp_enqueue_style('jquery-chosen');
    wp_register_script('jquery-chosen', $js_dir . 'chosen.jquery' . $suffix . '.js', array('jquery'), EDD_VERSION);
    wp_enqueue_script('jquery-chosen');
    wp_register_script('edd-admin-scripts', $js_dir . 'admin-scripts' . $suffix . '.js', array('jquery'), EDD_VERSION, false);
    wp_enqueue_script('edd-admin-scripts');
    wp_localize_script('edd-admin-scripts', 'edd_vars', array('post_id' => isset($post->ID) ? $post->ID : null, 'edd_version' => EDD_VERSION, 'add_new_download' => __('Add New Download', 'edd'), 'use_this_file' => __('Use This File', 'edd'), 'quick_edit_warning' => __('Sorry, not available for variable priced products.', 'edd'), 'delete_payment' => __('Are you sure you wish to delete this payment?', 'edd'), 'delete_payment_note' => __('Are you sure you wish to delete this note?', 'edd'), 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'edd'), 'revoke_api_key' => __('Are you sure you wish to revoke this API key?', 'edd'), 'regenerate_api_key' => __('Are you sure you wish to regenerate this API key?', 'edd'), 'resend_receipt' => __('Are you sure you wish to resend the purchase receipt?', 'edd'), 'copy_download_link_text' => __('Copy these links to your clipboard and give them to your customer', 'edd'), 'delete_payment_download' => sprintf(__('Are you sure you wish to delete this %s?', 'edd'), edd_get_label_singular()), 'one_price_min' => __('You must have at least one price', 'edd'), 'one_field_min' => __('You must have at least one field', 'edd'), 'one_download_min' => __('Payments must contain at least one item', 'edd'), 'one_option' => sprintf(__('Choose a %s', 'edd'), edd_get_label_singular()), 'one_or_more_option' => sprintf(__('Choose one or more %s', 'edd'), edd_get_label_plural()), 'numeric_item_price' => __('Item price must be numeric', 'edd'), 'numeric_quantity' => __('Quantity must be numeric', 'edd'), 'currency' => edd_get_currency(), 'currency_sign' => edd_currency_filter(''), 'currency_pos' => edd_get_option('currency_position', 'before'), 'currency_decimals' => edd_currency_decimal_filter(), 'new_media_ui' => apply_filters('edd_use_35_media_ui', 1), 'remove_text' => __('Remove', 'edd'), 'type_to_search' => sprintf(__('Type to search %s', 'edd'), edd_get_label_plural()), 'quantities_enabled' => edd_item_quantities_enabled()));
    wp_enqueue_style('wp-color-picker');
    wp_enqueue_script('wp-color-picker');
    wp_register_style('colorbox', $css_dir . 'colorbox' . $suffix . '.css', array(), '1.3.20');
    wp_enqueue_style('colorbox');
    wp_register_script('colorbox', $js_dir . 'jquery.colorbox-min.js', array('jquery'), '1.3.20');
    wp_enqueue_script('colorbox');
    if (function_exists('wp_enqueue_media') && version_compare($wp_version, '3.5', '>=')) {
        //call for new media manager
        wp_enqueue_media();
    }
    wp_register_script('jquery-flot', $js_dir . 'jquery.flot' . $suffix . '.js');
    wp_enqueue_script('jquery-flot');
    wp_enqueue_script('jquery-ui-datepicker');
    wp_enqueue_script('jquery-ui-dialog');
    $ui_style = 'classic' == get_user_option('admin_color') ? 'classic' : 'fresh';
    wp_register_style('jquery-ui-css', $css_dir . 'jquery-ui-' . $ui_style . $suffix . '.css');
    wp_enqueue_style('jquery-ui-css');
    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    wp_enqueue_style('thickbox');
    wp_register_style('edd-admin', $css_dir . 'edd-admin' . $suffix . '.css', EDD_VERSION);
    wp_enqueue_style('edd-admin');
}
/**
 * Override the standard quantity field for non-variably priced products
 *
 * @since       1.2.10
 * @param       int $download_id The ID of this download
 * @param       array $args Array of arguments
 * @return      void
 */
function edd_pl_download_purchase_form_quantity_field($download_id = 0, $args = array())
{
    global $edd_prices_sold_out;
    if (!edd_item_quantities_enabled()) {
        return;
    }
    if (edd_item_in_cart($download_id) && !edd_has_variable_prices($download_id)) {
        return;
    }
    if (edd_single_price_option_mode($download_id) && edd_has_variable_prices($download_id) && !edd_item_in_cart($download_id)) {
        return;
    }
    if (edd_single_price_option_mode($download_id) && edd_has_variable_prices($download_id) && edd_item_in_cart($download_id)) {
        return;
    }
    if (!edd_single_price_option_mode($download_id) && edd_has_variable_prices($download_id) && edd_item_in_cart($download_id)) {
        return;
    }
    // Get options
    $scope = edd_get_option('edd_purchase_limit_scope') ? edd_get_option('edd_purchase_limit_scope') : 'site-wide';
    $max_purchases = edd_pl_get_file_purchase_limit($download_id);
    $disabled = '';
    if ($scope == 'site-wide') {
        $purchases = edd_get_download_sales_stats($download_id);
    } elseif (is_user_logged_in()) {
        $purchases = edd_pl_get_user_purchase_count(get_current_user_id(), $download_id);
    }
    if ($purchases) {
        if ($max_purchases && $purchases >= $max_purchases || !empty($edd_prices_sold_out)) {
            $disabled = 'disabled="disabled"';
        }
    }
    $max = 'max="" ';
    if ($max_purchases) {
        $remaining = $max_purchases - $purchases;
        $max = 'max="' . $remaining . '" ';
    }
    echo '<div class="edd_download_quantity_wrapper">';
    echo '<input type="number" min="1" ' . $max . 'step="1" ' . $disabled . 'name="edd_download_quantity" class="edd-input edd-item-quantity" value="1" />';
    echo '</div>';
}
 /**
  * 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;
 }
/**
 * Email template tag: download_list
 * A list of download links for each download purchased in plaintext
 *
 * @since 2.1.1
 * @param int $payment_id
 *
 * @return string download_list
 */
function edd_email_tag_download_list_plain($payment_id)
{
    $payment_data = edd_get_payment_meta($payment_id);
    $cart_items = edd_get_payment_meta_cart_details($payment_id);
    $email = edd_get_payment_user_email($payment_id);
    $download_list = '';
    if ($cart_items) {
        $show_names = apply_filters('edd_email_show_names', true);
        $show_links = apply_filters('edd_email_show_links', true);
        foreach ($cart_items as $item) {
            if (edd_use_skus()) {
                $sku = edd_get_download_sku($item['id']);
            }
            if (edd_item_quantities_enabled()) {
                $quantity = $item['quantity'];
            }
            $price_id = edd_get_cart_item_price_id($item);
            if ($show_names) {
                $title = get_the_title($item['id']);
                if (!empty($quantity) && $quantity > 1) {
                    $title .= __('Quantity', 'easy-digital-downloads') . ': ' . $quantity;
                }
                if (!empty($sku)) {
                    $title .= __('SKU', 'easy-digital-downloads') . ': ' . $sku;
                }
                if ($price_id !== null) {
                    $title .= edd_get_price_option_name($item['id'], $price_id, $payment_id);
                }
                $download_list .= "\n";
                $download_list .= apply_filters('edd_email_receipt_download_title', $title, $item, $price_id, $payment_id) . "\n";
            }
            $files = edd_get_download_files($item['id'], $price_id);
            if (!empty($files)) {
                foreach ($files as $filekey => $file) {
                    if ($show_links) {
                        $download_list .= "\n";
                        $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $item['id'], $price_id);
                        $download_list .= edd_get_file_name($file) . ': ' . $file_url . "\n";
                    } else {
                        $download_list .= "\n";
                        $download_list .= edd_get_file_name($file) . "\n";
                    }
                }
            } elseif (edd_is_bundled_product($item['id'])) {
                $bundled_products = apply_filters('edd_email_tag_bundled_products', edd_get_bundled_products($item['id']), $item, $payment_id, 'download_list');
                foreach ($bundled_products as $bundle_item) {
                    $download_list .= '<div class="edd_bundled_product"><strong>' . get_the_title($bundle_item) . '</strong></div>';
                    $files = edd_get_download_files($bundle_item);
                    foreach ($files as $filekey => $file) {
                        if ($show_links) {
                            $file_url = edd_get_download_file_url($payment_data['key'], $email, $filekey, $bundle_item, $price_id);
                            $download_list .= $file['name'] . ': ' . $file_url . "\n";
                        } else {
                            $download_list .= $file['name'] . "\n";
                        }
                    }
                }
            }
            if ('' != edd_get_product_notes($item['id'])) {
                $download_list .= "\n";
                $download_list .= edd_get_product_notes($item['id']) . "\n";
            }
        }
    }
    return $download_list;
}
/**
 * Load Admin Scripts
 *
 * Enqueues the required admin scripts.
 *
 * @since 1.0
 * @global $post
 * @param string $hook Page hook
 * @return void
 */
function edd_load_admin_scripts($hook)
{
    if (!apply_filters('edd_load_admin_scripts', edd_is_admin_page(), $hook)) {
        return;
    }
    global $post;
    $js_dir = EDD_PLUGIN_URL . 'assets/js/';
    $css_dir = EDD_PLUGIN_URL . 'assets/css/';
    // Use minified libraries if SCRIPT_DEBUG is turned off
    $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
    // These have to be global
    wp_register_style('jquery-chosen', $css_dir . 'chosen' . $suffix . '.css', array(), EDD_VERSION);
    wp_enqueue_style('jquery-chosen');
    wp_register_script('jquery-chosen', $js_dir . 'chosen.jquery' . $suffix . '.js', array('jquery'), EDD_VERSION);
    wp_enqueue_script('jquery-chosen');
    wp_enqueue_script('jquery-form');
    $admin_deps = array();
    if (!edd_is_admin_page($hook, 'edit') && !edd_is_admin_page($hook, 'new')) {
        $admin_deps = array('jquery', 'jquery-form', 'inline-edit-post');
    } else {
        $admin_deps = array('jquery', 'jquery-form');
    }
    wp_register_script('edd-admin-scripts', $js_dir . 'admin-scripts' . $suffix . '.js', $admin_deps, EDD_VERSION, false);
    wp_enqueue_script('edd-admin-scripts');
    wp_localize_script('edd-admin-scripts', 'edd_vars', array('post_id' => isset($post->ID) ? $post->ID : null, 'edd_version' => EDD_VERSION, 'add_new_download' => __('Add New Download', 'easy-digital-downloads'), 'use_this_file' => __('Use This File', 'easy-digital-downloads'), 'quick_edit_warning' => __('Sorry, not available for variable priced products.', 'easy-digital-downloads'), 'delete_payment' => __('Are you sure you wish to delete this payment?', 'easy-digital-downloads'), 'delete_payment_note' => __('Are you sure you wish to delete this note?', 'easy-digital-downloads'), 'delete_tax_rate' => __('Are you sure you wish to delete this tax rate?', 'easy-digital-downloads'), 'revoke_api_key' => __('Are you sure you wish to revoke this API key?', 'easy-digital-downloads'), 'regenerate_api_key' => __('Are you sure you wish to regenerate this API key?', 'easy-digital-downloads'), 'resend_receipt' => __('Are you sure you wish to resend the purchase receipt?', 'easy-digital-downloads'), 'copy_download_link_text' => __('Copy these links to your clipboard and give them to your customer', 'easy-digital-downloads'), 'delete_payment_download' => sprintf(__('Are you sure you wish to delete this %s?', 'easy-digital-downloads'), edd_get_label_singular()), 'one_price_min' => __('You must have at least one price', 'easy-digital-downloads'), 'one_field_min' => __('You must have at least one field', 'easy-digital-downloads'), 'one_download_min' => __('Payments must contain at least one item', 'easy-digital-downloads'), 'one_option' => sprintf(__('Choose a %s', 'easy-digital-downloads'), edd_get_label_singular()), 'one_or_more_option' => sprintf(__('Choose one or more %s', 'easy-digital-downloads'), edd_get_label_plural()), 'numeric_item_price' => __('Item price must be numeric', 'easy-digital-downloads'), 'numeric_quantity' => __('Quantity must be numeric', 'easy-digital-downloads'), 'currency' => edd_get_currency(), 'currency_sign' => edd_currency_filter(''), 'currency_pos' => edd_get_option('currency_position', 'before'), 'currency_decimals' => edd_currency_decimal_filter(), 'new_media_ui' => apply_filters('edd_use_35_media_ui', 1), 'remove_text' => __('Remove', 'easy-digital-downloads'), 'type_to_search' => sprintf(__('Type to search %s', 'easy-digital-downloads'), edd_get_label_plural()), 'quantities_enabled' => edd_item_quantities_enabled(), 'batch_export_no_class' => __('You must choose a method.', 'easy-digital-downloads'), 'batch_export_no_reqs' => __('Required fields not completed.', 'easy-digital-downloads'), 'reset_stats_warn' => __('Are you sure you want to reset your store? This process is <strong><em>not reversible</em></strong>. Please be sure you have a recent backup.', 'easy-digital-downloads'), 'search_placeholder' => sprintf(__('Type to search all %s', 'easy-digital-downloads'), edd_get_label_plural()), 'search_placeholder_customer' => __('Type to search all Customers', 'easy-digital-downloads'), 'search_placeholder_country' => __('Type to search all Countries', 'easy-digital-downloads'), 'search_placeholder_state' => __('Type to search all States/Provinces', 'easy-digital-downloads'), 'unsupported_browser' => __('We are sorry but your browser is not compatible with this kind of file upload. Please upgrade your browser.', 'easy-digital-downloads')));
    wp_enqueue_style('wp-color-picker');
    wp_enqueue_script('wp-color-picker');
    wp_register_style('colorbox', $css_dir . 'colorbox' . $suffix . '.css', array(), '1.3.20');
    wp_enqueue_style('colorbox');
    wp_register_script('colorbox', $js_dir . 'jquery.colorbox-min.js', array('jquery'), '1.3.20');
    wp_enqueue_script('colorbox');
    //call for media manager
    wp_enqueue_media();
    wp_register_script('jquery-flot', $js_dir . 'jquery.flot' . $suffix . '.js');
    wp_enqueue_script('jquery-flot');
    wp_enqueue_script('jquery-ui-datepicker');
    wp_enqueue_script('jquery-ui-dialog');
    wp_enqueue_script('jquery-ui-tooltip');
    $ui_style = 'classic' == get_user_option('admin_color') ? 'classic' : 'fresh';
    wp_register_style('jquery-ui-css', $css_dir . 'jquery-ui-' . $ui_style . $suffix . '.css');
    wp_enqueue_style('jquery-ui-css');
    wp_enqueue_script('media-upload');
    wp_enqueue_script('thickbox');
    wp_enqueue_style('thickbox');
    wp_register_style('edd-admin', $css_dir . 'edd-admin' . $suffix . '.css', EDD_VERSION);
    wp_enqueue_style('edd-admin');
}
/**
 * Display the "Save Cart" button on the checkout
 *
 * @since 1.8
 * @return void
 */
function edd_update_cart_button()
{
    if (!edd_item_quantities_enabled()) {
        return;
    }
    $color = edd_get_option('checkout_color', 'blue');
    $color = $color == 'inherit' ? '' : $color;
    ?>
	<input type="submit" name="edd_update_cart_submit" class="edd-submit edd-no-js button<?php 
    echo ' ' . $color;
    ?>
" value="<?php 
    _e('Update Cart', 'easy-digital-downloads');
    ?>
"/>
	<input type="hidden" name="edd_action" value="update_cart"/>
<?php 
}
    public static function payment_creation_form()
    {
        // Determine our float accuracy for the steps and rounding
        $decimals = edd_currency_decimal_filter();
        if (empty($decimals)) {
            $step = 1;
        } else {
            $i = 1;
            $step = '0.';
            while ($i < $decimals) {
                $step .= '0';
                $i++;
            }
            $step .= '1';
            $step = (double) $step;
        }
        $tax_included = 'false';
        if (edd_use_taxes() && edd_prices_include_tax()) {
            $tax_included = 'true';
        }
        $columns = 4;
        ?>
		<div class="wrap">
			<h2><?php 
        _e('Create New Payment', 'edd-manual-purchases');
        ?>
</h2>
			<script type="text/javascript">
				jQuery(document).ready(function($) {

					$(document.body).on('input', '.edd-mp-amount,.edd-mp-tax,.edd-mp-quantity', function() {
						eddmp_update_total();
					});

					// check for variable prices
					$('#edd_mp_create_payment').on('change', '.mp-downloads', function() {
						var $this = $(this);
						var selected_download = $('option:selected', this).val();
						$this.parent().parent().find('.download-price-option-wrap').html('');
						if( parseInt( selected_download ) != 0) {
							var edd_mp_nonce = $('#edd_create_payment_nonce').val();
							var key = $this.parent().parent().data('key');
							$.ajax({
								type: "POST",
								url: ajaxurl,
								data: {
									action: 'edd_mp_check_for_variations',
									download_id: selected_download,
									key: key,
									nonce: edd_mp_nonce
								},
								dataType: "json",
								success: function(response) {
									$this.parent().parent().find('.download-price-option-wrap').html( response.html );
									$this.parent().parent().find('input[name="downloads['+ key +'][amount]"]').val( response.amount );
									eddmp_update_total();
								}
							}).fail(function (data) {
								if ( window.console && window.console.log ) {
									console.log( data );
								}
							});
						} else {
							$this.parent().parent().find('.download-price-option-wrap').html('N/A');
						}
					});

					// Update the price when a variation changes
					$('#edd_mp_create_payment').on('change', '.edd-mp-price-select', function() {
						var $this        = $(this);
						var price_id     = $('option:selected', this).val();
						var edd_mp_nonce = $('#edd_create_payment_nonce').val();
						var key          = $this.parent().parent().data('key');
						var download_id  = $('select[name="downloads[' + key + '][id]"]').val();

						$.ajax({
							type: "POST",
							url: ajaxurl,
							data: {
								action: 'edd_mp_variation_change',
								download_id: download_id,
								price_id: price_id,
								key: key,
								nonce: edd_mp_nonce
							},
							dataType: "json",
							success: function(response) {
								$this.parent().parent().find('input[name="downloads['+ key +'][amount]"]').val( response.amount );
								eddmp_update_total();
							}
						}).fail(function (data) {
							if ( window.console && window.console.log ) {
								console.log( data );
							}
						});

					});

					$('.edd_add_repeatable').click(function() {
						setTimeout( function() {
							$('.edd_repeatable_row:last').find('.download-price-option-wrap').html('');
							$('.edd_repeatable_row:last').find('.edd-mp-quantity').val('1');
						}, 300 );
					});

					$(document.body).on('click', '.edd_remove_repeatable', function() {
						setTimeout( function() {
							var row_count = $('.edd_repeatable_row').length;
							if ( 1 === row_count ) {
								var current_quantity = $('.edd_repeatable_row:first').find('.edd-mp-quantity').val();
								if ( '' === current_quantity ) {
									$('.edd_repeatable_row:first').find('.edd-mp-quantity').val('1');
								}
							}

							eddmp_update_total();
						}, 100 );
					});

					if ($('.form-table .edd_datepicker').length > 0) {
						var dateFormat = 'mm/dd/yy';
						$('.edd_datepicker').datepicker({
							dateFormat: dateFormat
						});
					}

					function eddmp_update_total() {
						// Setup some place holder vars for each row
						var item_amount   = 0;
						var item_tax      = 0;
						var item_quantity = 1;
						var item_total    = 0;

						// Our final total to show to the customer
						var total      = 0;

						var prices_include_tax = <?php 
        echo $tax_included;
        ?>
;

						// Iterate over each line item and add amount + tax * quantity to get the total
						$('.edd_repeatable_row').each(function() {
							var row = $(this);

							item_amount   = parseFloat( row.find('.edd-mp-amount').val() );

							if (row.find('.edd-mp-tax').length) {
								item_tax      = parseFloat(row.find('.edd-mp-tax').val() );

								if (! isNaN(item_tax) && ! prices_include_tax) {
									item_amount = item_amount + item_tax;
								}
							}

							if (row.find('.edd-mp-quantity').length) {
								item_quantity = parseFloat(row.find('.edd-mp-quantity').val() );
							}

							item_total  = item_amount * item_quantity;

							total += item_total;
						});

						if ( isNaN( total ) ){
							total = 0;
						}

						$('#edd-mp-total-amount').html(total.toFixed(<?php 
        echo $decimals;
        ?>
));
					}
				});
			</script>

			<form id="edd_mp_create_payment" method="post">
				<table class="form-table" id="edd-customer-details">
					<tbody id="edd-mp-table-body">
						<tr class="form-field edd-mp-download-wrap">
							<th scope="row" valign="top">
								<label><?php 
        echo edd_get_label_plural();
        ?>
</label>
							</th>
							<td class="edd-mp-downloads">
								<div id="edd_file_fields" class="edd_meta_table_wrap">
									<table class="widefat edd_repeatable_table" style="width: auto;" cellpadding="0" cellspacing="0">
										<thead>
											<tr>
												<th style="padding: 10px;"><?php 
        echo edd_get_label_plural();
        ?>
</th>
												<th style="padding: 10px;"><?php 
        _e('Price Option', 'edd-manual-purchases');
        ?>
</th>
												<th style="padding: 10px; width: 150px;"><?php 
        _e('Amount', 'edd-manual-purchases');
        ?>
</th>
												<?php 
        if (edd_use_taxes()) {
            ?>
													<th style="padding: 10px; width: 150px;"><?php 
            _e('Tax', 'edd-manual-purchases');
            ?>
</th>
													<?php 
            $columns++;
            ?>
												<?php 
        }
        if (edd_item_quantities_enabled()) {
            ?>
													<th style="padding: 10px; width: 50px;"><?php 
            _e('Quantity', 'edd-manual-purchases');
            ?>
</th>
													<?php 
            $columns++;
            ?>
												<?php 
        }
        ?>
												<th style="padding: 10px; width: 5px;"
											</tr>
										</thead>
										<tbody>
											<tr class="edd_repeatable_product_wrapper edd_repeatable_row" data-key="1">
												<td>
													<?php 
        echo EDD()->html->product_dropdown(array('name' => 'downloads[1][id]', 'id' => 'downloads', 'class' => 'mp-downloads', 'multiple' => false, 'chosen' => true));
        ?>
												</td>
												<td class="download-price-option-wrap"><?php 
        _e('N/A', 'edd-manual-purchases');
        ?>
</td>
												<td>
													<input type="number" step="<?php 
        echo $step;
        ?>
" class="edd-mp-amount" name="downloads[1][amount]" value="" min="0" placeholder="<?php 
        esc_attr_e('Item price', 'edd-manual-purchases');
        ?>
"/>
												</td>
												<?php 
        if (edd_use_taxes()) {
            ?>
													<td>
														<?php 
            if (!edd_prices_include_tax()) {
                ?>
														&nbsp;&plus;&nbsp;
														<?php 
            }
            ?>
														<input type="number" style="width: 65%" step="<?php 
            echo $step;
            ?>
" class="edd-mp-tax" name="downloads[1][tax]" value="" min="0" placeholder="<?php 
            esc_attr_e('Item Tax', 'edd-manual-purchases');
            ?>
"/>
													</td>
												<?php 
        }
        ?>
												<?php 
        if (edd_item_quantities_enabled()) {
            ?>
													<td>
														&nbsp;&times;&nbsp;<input type="number" step="1" class="edd-mp-quantity" style="width: 65%" name="downloads[1][quantity]" value="1" min="1" placeholder="<?php 
            esc_attr_e('Enter quantity', 'edd-manual-purchases');
            ?>
"/>
													</td>
												<?php 
        }
        ?>
												<td>
													<a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php 
        echo admin_url('/images/xit.gif');
        ?>
) no-repeat;">&times;</a>
												</td>
											</tr>
											<tr>
												<td class="submit" colspan="<?php 
        echo $columns;
        ?>
" style="float: none; clear:both; background: #fff;">
													<a class="button-secondary edd_add_repeatable" style="margin: 6px 0 10px;"><?php 
        _e('Add New', 'edd-manual-purchases');
        ?>
</a>
													<span style="line-height: 38px;">
														Total: <?php 
        echo edd_currency_symbol();
        ?>
<span id="edd-mp-total-amount">0.00</span>
														<?php 
        if (edd_use_taxes()) {
            ?>
															<sup>&dagger;</sup>
														<?php 
        }
        ?>
													</span>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
								<span>
									<small>
									<?php 
        if (edd_use_taxes()) {
            ?>
<sup>&dagger;</sup>
										<?php 
            if (!edd_prices_include_tax()) {
                ?>
											<em><?php 
                _e('Total is based on prices exclusive of tax.', 'edd-manual-purchases');
                ?>
</em>
										<?php 
            } else {
                ?>
											<em><?php 
                _e('Total is based on prices inclusive of tax.', 'edd-manual-purchases');
                ?>
</em>
										<?php 
            }
            ?>
									<?php 
        }
        ?>
									</small>
								</span>
							</td>
						</tr>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="edd-mp-user"><?php 
        _e('Customer', 'edd-manual-purchases');
        ?>
</label>
							</th>
							<td class="edd-mp-email">
								<div class="customer-info">
									<?php 
        echo EDD()->html->customer_dropdown(array('name' => 'customer'));
        ?>
								</div>
								<div class="description customer-info">
									<a href="#new" class="edd-payment-new-customer" title="<?php 
        _e('New Customer', 'edd-manual-purchases');
        ?>
"><?php 
        _e('Create new customer', 'edd-manual-purchases');
        ?>
</a>
								</div>
								<div class="description new-customer" style="display: none">
									<a href="#cancel" class="edd-payment-new-customer-cancel" title="<?php 
        _e('Existing Customer', 'edd-manual-purchases');
        ?>
"><?php 
        _e('Select existing customer', 'edd-manual-purchases');
        ?>
</a>
								</div>
							</td>
						</tr>
						<tr class="form-field new-customer" style="display: none">
							<th scope="row" valign="top">
								<label for="edd-mp-user"><?php 
        _e('Customer Email', 'edd-manual-purchases');
        ?>
</label>
							</th>
							<td class="edd-mp-email">
								<input type="text" class="small-text" id="edd-mp-email" name="email" style="width: 180px;"/>
								<div class="description"><?php 
        _e('Enter the email address of the customer.', 'edd-manual-purchases');
        ?>
</div>
							</td>
						</tr>
						<tr class="form-field new-customer" style="display: none">
							<th scope="row" valign="top">
								<label for="edd-mp-last"><?php 
        _e('Customer First Name', 'edd-manual-purchases');
        ?>
</label>
							</th>
							<td class="edd-mp-last">
								<input type="text" class="small-text" id="edd-mp-last" name="first" style="width: 180px;"/>
								<div class="description"><?php 
        _e('Enter the first name of the customer (optional).', 'edd-manual-purchases');
        ?>
</div>
							</td>
						</tr>
						<tr class="form-field new-customer" style="display: none">
							<th scope="row" valign="top">
								<label for="edd-mp-last"><?php 
        _e('Customer Last Name', 'edd-manual-purchases');
        ?>
</label>
							</th>
							<td class="edd-mp-last">
								<input type="text" class="small-text" id="edd-mp-last" name="last" style="width: 180px;"/>
								<div class="description"><?php 
        _e('Enter the last name of the customer (optional).', 'edd-manual-purchases');
        ?>
</div>
							</td>
						</tr>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="edd-mp-amount"><?php 
        _e('Amount', 'edd-manual-purchases');
        ?>
</label>
							</th>
							<td class="edd-mp-downloads">
								<input type="text" class="small-text" id="edd-mp-amount" name="amount" style="width: 180px;"/>
								<?php 
        if (edd_item_quantities_enabled()) {
            ?>
									<div class="description"><?php 
            _e('Enter the total purchase amount, or leave blank to auto calculate price based on the selected items and quantities above. Use 0.00 for 0.', 'edd-manual-purchases');
            ?>
</div>
								<?php 
        } else {
            ?>
									<div class="description"><?php 
            _e('Enter the total purchase amount, or leave blank to auto calculate price based on the selected items above. Use 0.00 for 0.', 'edd-manual-purchases');
            ?>
</div>
								<?php 
        }
        ?>
							</td>
						</tr>
						<tr class="form-field">
							<th scope="row" valign="top">
								<?php 
        _e('Payment status', 'edd-manual-purchases');
        ?>
							</th>
							<td class="edd-mp-status">
								<?php 
        echo EDD()->html->select(array('name' => 'status', 'options' => edd_get_payment_statuses(), 'selected' => 'publish', 'show_option_all' => false, 'show_option_none' => false));
        ?>
								<label for="edd-mp-status" class="description"><?php 
        _e('Select the status of this payment.', 'edd-manual-purchases');
        ?>
</label>
							</td>
						</tr>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="edd-mp-payment-method"><?php 
        _e('Payment Method', 'edd-manual-purchases');
        ?>
</label>
							</th>
							<td class="edd-mp-gateways">
								<select name="gateway" id="edd-mp-payment-method">
									<option value="manual_purchases"><?php 
        esc_html_e('Manual Payment', 'edd-manual-purchases');
        ?>
</option>
									<?php 
        foreach (edd_get_payment_gateways() as $gateway_id => $gateway) {
            ?>
										<option value="<?php 
            echo esc_attr($gateway_id);
            ?>
"><?php 
            echo esc_html($gateway['admin_label']);
            ?>
</option>
									<?php 
        }
        ?>
								</select>
								<div class="description"><?php 
        _e('Select the payment method used.', 'edd-manual-purchases');
        ?>
</div>
							</td>
						</tr>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="edd-mp-transaction-id"><?php 
        _e('Transaction ID', 'edd-manual-purchases');
        ?>
</label>
							</th>
							<td class="edd-mp-downloads">
								<input type="text" class="small-text" id="edd-mp-transaction-id" name="transaction_id" style="width: 180px;"/>
								<div class="description"><?php 
        _e('Enter the transaction ID, if any.', 'edd-manual-purchases');
        ?>
</div>
							</td>
						</tr>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="edd-mp-date"><?php 
        _e('Date', 'edd-manual-purchases');
        ?>
</label>
							</th>
							<td class="edd-mp-downloads">
								<input type="text" class="small-text edd_datepicker" id="edd-mp-date" name="date" style="width: 180px;"/>
								<div class="description"><?php 
        _e('Enter the purchase date, or leave blank for today\'s date.', 'edd-manual-purchases');
        ?>
</div>
							</td>
						</tr>
						<?php 
        if (function_exists('eddc_record_commission')) {
            ?>
						<tr class="form-field">
							<th scope="row" valign="top">
								<?php 
            _e('Commission', 'edd-manual-purchases');
            ?>
							</th>
							<td class="edd-mp-downloads">
								<label for="edd-mp-commission">
									<input type="checkbox" id="edd-mp-commission" name="commission" style="width: auto;"/>
									<?php 
            _e('Record commissions (if any) for this manual purchase?', 'edd-manual-purchases');
            ?>
								</label>
							</td>
						</tr>
						<?php 
        }
        ?>
						<?php 
        if (class_exists('EDD_Simple_Shipping')) {
            ?>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="edd-mp-shipped"><?php 
            _e('Shipped', 'edd-manual-purchases');
            ?>
</label>
							</th>
							<td class="edd-mp-shipped">
								<label for="edd-mp-shipped">
									<input type="checkbox" id="edd-mp-shipped" name="shipped" style="width: auto;"/>
									<?php 
            _e('Mark order as shipped?', 'edd-manual-purchases');
            ?>
								</label>
							</td>
						</tr>
						<?php 
        }
        ?>
						<?php 
        if (class_exists('EDD_Wallet')) {
            ?>
						<tr class="form-field">
							<th scope="row" valign="top">
								<label for="edd-mp-wallet"><?php 
            _e('Pay From Wallet', 'edd-manual-purchases');
            ?>
</label>
							</th>
							<td class="edd-mp-wallet">
								<label for="edd-mp-wallet">
									<input type="checkbox" id="edd-mp-wallet" name="wallet" style="width: auto;"/>
									<?php 
            _e('Use funds from the customers\' wallet to pay for this payment.', 'edd-manual-purchases');
            ?>
								</label>
							</td>
						</tr>
						<?php 
        }
        ?>
						<tr class="form-field">
							<th scope="row" valign="top">
								<?php 
        _e('Send Receipt', 'edd-manual-purchases');
        ?>
							</th>
							<td class="edd-mp-receipt">
								<label for="edd-mp-receipt">
									<input type="checkbox" id="edd-mp-receipt" name="receipt" style="width: auto;" checked="1" value="1"/>
									<?php 
        _e('Send the purchase receipt to the buyer?', 'edd-manual-purchases');
        ?>
								</label>
							</td>
						</tr>
					</tbody>
				</table>
				<?php 
        wp_nonce_field('edd_create_payment_nonce', 'edd_create_payment_nonce');
        ?>
				<input type="hidden" name="edd-gateway" value="manual_purchases"/>
				<input type="hidden" name="edd-action" value="create_payment" />
				<?php 
        submit_button(__('Create Payment', 'edd-manual-purchases'));
        ?>
			</form>
		</div>
		<?php 
    }
/**
 * Display the "Save Cart" button on the checkout
 *
 * @since 1.8
 * @global $edd_options Array of all the EDD Options
 * @return void
 */
function edd_update_cart_button()
{
    global $edd_options;
    if (!edd_item_quantities_enabled()) {
        return;
    }
    $color = isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue';
    $color = $color == 'inherit' ? '' : $color;
    ?>
	<input type="submit" name="edd_update_cart_submit" class="edd-submit edd-no-js button<?php 
    echo ' ' . $color;
    ?>
" value="<?php 
    _e('Update Cart', 'edd');
    ?>
"/>
	<input type="hidden" name="edd_action" value="update_cart"/>
<?php 
}