/** * Payment actions * * @since 1.1 */ function edd_csau_payment_actions($payment_id) { $cart_details = edd_get_payment_meta_cart_details($payment_id); if (is_array($cart_details)) { // Increase purchase count and earnings foreach ($cart_details as $download) { // "bundle" or "default" $download_type = edd_get_download_type($download['id']); $price_id = isset($download['options']['price_id']) ? (int) $download['options']['price_id'] : false; // Increase earnings, and fire actions once per quantity number for ($i = 0; $i < $download['quantity']; $i++) { if (!edd_is_test_mode() || apply_filters('edd_log_test_payment_stats', false)) { if (isset($download['item_number']['cross_sell'])) { $type = 'cross_sell'; } elseif (isset($download['item_number']['upsell'])) { $type = 'upsell'; } else { $type = null; } if ($type) { edd_csau_increase_purchase_count($download['id'], $type); edd_csau_increase_earnings($download['id'], $download['price'], $type); edd_csau_record_sale_in_log($download['id'], $payment_id, $price_id, $type); } } $types[] = $type; $types = array_unique(array_filter($types)); } } // Clear the total earnings cache delete_transient('edd_' . $type . '_earnings_total'); } if ($types) { foreach ($types as $type) { // store the total amount of cross-sell earnings update_post_meta($payment_id, '_edd_payment_' . $type . '_total', edd_csau_calculate_sales($payment_id, $type)); $amount = edd_csau_get_payment_amount($payment_id, $type); // increase earnings edd_csau_increase_total_earnings($amount, $type); } } }
function kjm_render_products_field($post_id) { $type = edd_get_download_type($post_id); $display = $type == 'bundle' ? '' : ' style="display:none;"'; $products = edd_get_bundled_products($post_id); ?> <div id="edd_products"<?php echo $display; ?> > <div id="edd_file_fields" class="edd_meta_table_wrap"> <table class="widefat" width="100%" cellpadding="0" cellspacing="0"> <thead> <tr> <th><?php printf(__('Bundled %s:', 'easy-digital-downloads'), edd_get_label_plural()); ?> </th> <?php do_action('edd_download_products_table_head', $post_id); ?> </tr> </thead> <tbody> <tr class="edd_repeatable_product_wrapper"> <td> <?php echo EDD()->html->product_dropdown(array('name' => '_edd_bundled_products[]', 'id' => 'edd_bundled_products', 'selected' => $products, 'multiple' => true, 'chosen' => true, 'bundles' => false, 'number' => 2)); ?> </td> <?php do_action('edd_download_products_table_row', $post_id); ?> </tr> </tbody> </table> </div> </div> <?php }
echo '<input type="number" name="edd_plans_multiple_license[' . $key . '][length]" class="small-text" value="' . $length_default . '"/> '; echo '<select name="edd_plans_multiple_license[' . $key . '][unit]">'; echo '<option value="days"' . selected('days', $unit_default, false) . '>' . __('Days', 'edd_plans') . '</option>'; echo '<option value="weeks"' . selected('weeks', $unit_default, false) . '>' . __('Weeks', 'edd_plans') . '</option>'; echo '<option value="months"' . selected('months', $unit_default, false) . '>' . __('Months', 'edd_plans') . '</option>'; echo '<option value="years"' . selected('years', $unit_default, false) . '>' . __('Years', 'edd_plans') . '</option>'; echo '</select> '; echo '</td>'; } function edd_plans_multiple_license_header($download_id) { edd_plans_load_multiple_license(); if ('bundle' == edd_get_download_type($download_id)) { return; } ?> <th></th>
/** * Calculate Total Bought Points * * Handles to calculate total bought * points for cart data * * @package Easy Digital Downloads - Points and Rewards * @since 1.1.0 **/ public function edd_points_get_bought_points($cartdata) { $points = 0; //check cart not empty if (!empty($cartdata)) { //calculate bought price foreach ($cartdata as $items) { //check download type is points if (edd_get_download_type($items['id']) == 'points') { //check item of options set then consider that if (isset($items['options'])) { $itemoptions = $items['options']; } elseif (isset($items['item_number']['options'])) { $itemoptions = $items['item_number']['options']; } else { $itemoptions = array(); } //get cart item price $downloadprice = edd_get_cart_item_price($items['id'], $itemoptions) * $items['quantity']; //get buy points from download $points += $this->edd_points_get_download_buy_points($downloadprice); } //end if to check download type is points } //end foreach loop } //check cart data should not empty //return points return $points; }
/** * File Download Limit Row * * The file download limit is the maximum number of times each file * can be downloaded by the buyer * * @since 1.3.1 * @param int $post_id Download (Post) ID * @return void */ function edd_render_download_limit_row($post_id) { if (!current_user_can('manage_shop_settings')) { return; } $edd_download_limit = edd_get_file_download_limit($post_id); $display = 'bundle' == edd_get_download_type($post_id) ? ' style="display: none;"' : ''; ?> <div id="edd_download_limit_wrap"<?php echo $display; ?> > <p><strong><?php _e('File Download Limit:', 'edd'); ?> </strong></p> <label for="edd_download_limit"> <?php echo EDD()->html->text(array('name' => '_edd_download_limit', 'value' => $edd_download_limit, 'class' => 'small-text')); ?> <?php _e('Leave blank for global setting or 0 for unlimited', 'edd'); ?> </label> </div> <?php }
/** * Complete a purchase * * Performs all necessary actions to complete a purchase. * Triggered by the edd_update_payment_status() function. * * @since 1.0.8.3 * @param int $payment_id the ID number of the payment * @param string $new_status the status of the payment, probably "publish" * @param string $old_status the status of the payment prior to being marked as "complete", probably "pending" * @return void */ function edd_complete_purchase($payment_id, $new_status, $old_status) { if ($old_status == 'publish' || $old_status == 'complete') { return; } // Make sure that payments are only completed once // Make sure the payment completion is only processed when new status is complete if ($new_status != 'publish' && $new_status != 'complete') { return; } $creation_date = get_post_field('post_date', $payment_id, 'raw'); $completed_date = edd_get_payment_completed_date($payment_id); $user_info = edd_get_payment_meta_user_info($payment_id); $customer_id = edd_get_payment_customer_id($payment_id); $amount = edd_get_payment_amount($payment_id); $cart_details = edd_get_payment_meta_cart_details($payment_id); do_action('edd_pre_complete_purchase', $payment_id); if (is_array($cart_details)) { // Increase purchase count and earnings foreach ($cart_details as $cart_index => $download) { // "bundle" or "default" $download_type = edd_get_download_type($download['id']); $price_id = isset($download['item_number']['options']['price_id']) ? (int) $download['item_number']['options']['price_id'] : false; // Increase earnings and fire actions once per quantity number for ($i = 0; $i < $download['quantity']; $i++) { // Ensure these actions only run once, ever if (empty($completed_date)) { edd_record_sale_in_log($download['id'], $payment_id, $price_id, $creation_date); do_action('edd_complete_download_purchase', $download['id'], $payment_id, $download_type, $download, $cart_index); } } // Increase the earnings for this download ID edd_increase_earnings($download['id'], $download['price']); edd_increase_purchase_count($download['id'], $download['quantity']); } // Clear the total earnings cache delete_transient('edd_earnings_total'); // Clear the This Month earnings (this_monththis_month is NOT a typo) delete_transient(md5('edd_earnings_this_monththis_month')); delete_transient(md5('edd_earnings_todaytoday')); } // Increase the customer's purchase stats $customer = new EDD_Customer($customer_id); $customer->increase_purchase_count(); $customer->increase_value($amount); edd_increase_total_earnings($amount); // Check for discount codes and increment their use counts if (!empty($user_info['discount']) && $user_info['discount'] !== 'none') { $discounts = array_map('trim', explode(',', $user_info['discount'])); if (!empty($discounts)) { foreach ($discounts as $code) { edd_increase_discount_usage($code); } } } // Ensure this action only runs once ever if (empty($completed_date)) { // Save the completed date edd_update_payment_meta($payment_id, '_edd_completed_date', current_time('mysql')); do_action('edd_complete_purchase', $payment_id); } // Empty the shopping cart edd_empty_cart(); }
/** * Send purchase details to MailChimp's Ecommerce360 extension. * * @param integer $payment_id [description] * @return bool */ public function record_ecommerce360_purchase($payment_id = 0) { // Make sure an API key has been entered if (empty($this->key)) { return FALSE; } // Don't record details if we're in test mode if (edd_is_test_mode()) { return FALSE; } $payment = edd_get_payment_meta($payment_id); $user_info = edd_get_payment_meta_user_info($payment_id); $amount = edd_get_payment_amount($payment_id); $cart_details = edd_get_payment_meta_cart_details($payment_id); $tax = edd_get_payment_tax($payment_id); if (is_array($cart_details)) { $items = array(); // Increase purchase count and earnings foreach ($cart_details as $index => $download) { // Get the categories that this download belongs to, if any $post = edd_get_download($download['id']); $terms = get_the_terms($download['id'], 'download_category'); if ($terms && !is_wp_error($terms)) { $categories = array(); foreach ($terms as $term) { $categories[] = $term->name; } $category_id = $terms[0]->term_id; $category_name = join(" - ", $categories); } else { $category_id = 1; $category_name = 'Download'; } // "bundle" or "default" $download_type = edd_get_download_type($download['id']); $download['sku'] = edd_get_download_sku($download['id']); // if ( 'bundle' == $download_type ) { // $downloads = edd_get_bundled_products( $download_id ); // if ( $downloads ) { // foreach ( $downloads as $d_id ) { // # Do something // } // } // } $item = array('line_num' => $index + 1, 'product_id' => (int) $download['id'], 'product_name' => $download['name'], 'category_id' => $category_id, 'category_name' => $category_name, 'qty' => $download['quantity'], 'cost' => $download['subtotal']); if ($download['sku'] !== '-') { $item['sku'] = $download['sku']; // optional, 30 char limit } $items[] = $item; } $order = array('id' => (string) $payment_id, 'email' => $user_info['email'], 'total' => $amount, 'store_id' => self::_edd_ec360_get_store_id(), 'store_name' => home_url(), 'items' => $items, 'order_date' => get_the_date('Y-n-j', $payment_id)); // Set Ecommerce360 variables if they exist $campaign_id = get_post_meta($payment_id, '_edd_mc_campaign_id', true); $email_id = get_post_meta($payment_id, '_edd_mc_email_id', true); if (!empty($campaign_id)) { $order['campaign_id'] = $campaign_id; } if (!empty($email_id)) { $order['email_id'] = $email_id; } if ($tax != 0) { $order['tax'] = $tax; // double, optional } // Send to MailChimp $options = array('CURLOPT_FOLLOWLOCATION' => false); $mailchimp = new EDD_MailChimp_API($this->key, $options); try { $result = $mailchimp->call('ecomm/order-add', array('order' => $order)); edd_insert_payment_note($payment_id, __('Order details have been added to MailChimp successfully', 'eddmc')); } catch (Exception $e) { edd_insert_payment_note($payment_id, __('MailChimp Ecommerce360 Error: ', 'eddmc') . $e->getMessage()); return FALSE; } return TRUE; } else { return FALSE; } }
/** * Determines if a product is a bundle * * @since 1.6 * @param int $download_id Download ID * @return bool */ function edd_is_bundled_product($download_id = 0) { return 'bundle' === edd_get_download_type($download_id); }
/** * Get the cart_details Key from Payment Meta * * @since 1.2 * @param int $payment_id Payment ID * @param bool $include_bundle_files Whether to retrieve product IDs associated with a bundled product and return them in the array * @return array $cart_details Cart Details Meta Values */ function edd_get_payment_meta_cart_details($payment_id, $include_bundle_files = false) { $payment_meta = edd_get_payment_meta($payment_id); $cart_details = !empty($payment_meta['cart_details']) ? maybe_unserialize($payment_meta['cart_details']) : array(); if (!empty($cart_details) && is_array($cart_details)) { foreach ($cart_details as $key => $cart_item) { // Ensure subtotal is set, for pre-1.9 orders if (!isset($cart_item['subtotal'])) { $cart_details[$key]['subtotal'] = $cart_item['price']; } if ($include_bundle_files) { if ('bundle' != edd_get_download_type($cart_item['id'])) { continue; } $products = edd_get_bundled_products($cart_item['id']); if (empty($products)) { continue; } foreach ($products as $product_id) { $cart_details[] = array('id' => $product_id, 'name' => get_the_title($product_id), 'item_number' => array('id' => $product_id, 'options' => array()), 'price' => 0, 'subtotal' => 0, 'quantity' => 1, 'tax' => 0, 'in_bundle' => 1, 'parent' => array('id' => $cart_item['id'], 'options' => isset($cart_item['item_number']['options']) ? $cart_item['item_number']['options'] : array())); } } } } return apply_filters('edd_payment_meta_cart_details', $cart_details, $payment_id); }
/** * Output our field field metabox sections * @since 1.0 * @param integer $post_id * @return void */ public function edd_files_fields($post_id = 0) { $type = edd_get_download_type($post_id); $files = edd_get_download_files($post_id); $variable_pricing = edd_has_variable_prices($post_id); $display = $type == 'bundle' ? ' style="display:none;"' : ''; $variable_display = $variable_pricing ? '' : 'display:none;'; ?> <div id="edd_download_files"<?php echo $display; ?> > <p> <strong><?php _e('File Downloads:', 'edd-git'); ?> </strong> </p> <div id="edd_git_error" style="color:red;"> </div> <input type="hidden" id="edd_download_files" class="edd_repeatable_upload_name_field" value=""/> <div id="edd_file_fields" class="edd_meta_table_wrap"> <table class="widefat edd_repeatable_table" width="100%" cellpadding="0" cellspacing="0"> <thead> <tr> <!--drag handle column. Disabled until we can work out a way to solve the issues raised here: https://github.com/easydigitaldownloads/Easy-Digital-Downloads/issues/1066 <th style="width: 20px"></th> --> <th style="width: 20%"><?php _e('Git Repo', 'edd-git'); ?> </th> <th style="width: 5%"></th> <th style="width: 10%;"><?php _e('Version Tag', 'edd-git'); ?> </th> <th style="width: 20%"><?php _e('File Name', 'edd-git'); ?> </th> <th style="width: 20%"><?php _e('Plugin Folder Name', 'edd-git'); ?> </th> <th style="width: 10%"></th> <th class="pricing" style="width: 10%; <?php echo $variable_display; ?> "><?php _e('Price Assignment', 'edd-git'); ?> </th> <?php do_action('edd_download_file_table_head', $post_id); ?> <th style="width: 2%"></th> </tr> </thead> <tbody> <?php if (!empty($files) && is_array($files)) { $files = array_slice($files, 0, 1); foreach ($files as $key => $value) { $name = isset($value['name']) ? $value['name'] : ''; $file = isset($value['file']) ? $value['file'] : ''; $condition = isset($value['condition']) ? $value['condition'] : false; $attachment_id = isset($value['attachment_id']) ? absint($value['attachment_id']) : false; $git_url = isset($value['git_url']) ? $value['git_url'] : ''; $git_folder_name = isset($value['git_folder_name']) ? $value['git_folder_name'] : ''; $git_version = isset($value['git_version']) ? $value['git_version'] : ''; $args = apply_filters('edd_file_row_args', compact('name', 'file', 'condition', 'attachment_id', 'git_url', 'git_folder_name', 'git_version'), $value); ?> <tr class="edd_repeatable_upload_wrapper edd_repeatable_row" data-key="<?php echo esc_attr($key); ?> "> <?php do_action('edd_render_file_row', 0, $args, $post_id); ?> </tr> <?php } } else { ?> <tr class="edd_repeatable_upload_wrapper edd_repeatable_row"> <?php do_action('edd_render_file_row', 0, array(), $post_id); ?> </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 10px;"><?php _e('Add New File', 'edd-git'); ?> </a> </td> </tr> </tbody> </table> </div> </div> <?php }
/** * Adds variable price role option. * * @since 1.0.0 * @access public * @param int $download_id * @param int $price_id * @param array $args * @return bool */ function role_map_edd_price_option_role($download_id, $price_id, $args) { if ('bundle' == edd_get_download_type($download_id)) { return; } // Get price role value. $role_map_edd_role = role_map_edd_get_price_option_role($download_id, $price_id); // Get membership length enabled for deciding when to show membership length option $edd_members_length_enabled = get_post_meta($download_id, '_edd_members_length_enabled', true) ? true : false; $edd_members_display = $edd_members_length_enabled ? '' : ' style="display:none;"'; ?> <td <?php echo $edd_members_display; ?> class="edd-members-toggled-hide"> <select name="edd_variable_prices[<?php echo $price_id; ?> ][role_map_edd_role]" id="edd_variable_prices[<?php echo $price_id; ?> ][role_map_edd_role]"> <?php foreach (role_map_edd_get_membership_role_names() as $role => $name) { ?> <option value="<?php echo esc_attr($role); ?> " <?php selected($role, $role_map_edd_role); ?> ><?php echo esc_html($name); ?> </option> <?php } ?> </select> </td> <?php }
/** * File Download Limit Row * * The file download limit is the maximum number of times each file * can be downloaded by the buyer * * @since 1.3.1 * @param int $post_id Download (Post) ID * @return void */ function edd_render_download_limit_row($post_id) { if (!current_user_can('manage_shop_settings')) { return; } $edd_download_limit = edd_get_file_download_limit($post_id); $display = 'bundle' == edd_get_download_type($post_id) ? ' style="display: none;"' : ''; ?> <div id="edd_download_limit_wrap"<?php echo $display; ?> > <p><strong><?php _e('File Download Limit:', 'easy-digital-downloads'); ?> </strong></p> <label for="edd_download_limit"> <?php echo EDD()->html->text(array('name' => '_edd_download_limit', 'value' => $edd_download_limit, 'class' => 'small-text')); ?> <?php _e('Leave blank for global setting or 0 for unlimited', 'easy-digital-downloads'); ?> </label> <span alt="f223" class="edd-help-tip dashicons dashicons-editor-help" title="<?php _e('<strong>File Download Limit</strong>: Limit the number of times a customer who purchased this product can access their download links.', 'easy-digital-downloads'); ?> "></span> </div> <?php }
/** * Add ReadMe Meta Box * * @since 2.4 */ function edd_sl_add_readme_meta_box() { global $post; if (!edd_get_option('edd_sl_readme_parsing')) { return; } if ('bundle' == edd_get_download_type(get_the_ID())) { return; } // ReadMe functionality add_meta_box('edd_sl_readme_box', __('Download <code>readme.txt</code> Configuration', 'edd_sl'), 'edd_sl_readme_meta_box_render', 'download', 'normal', 'default'); }
/** * Save our extra meta box fields * * @package Easy Digital Downloads - Points and Rewards * @since 1.0.0 */ public function edd_points_meta_fields_save($post_id) { global $post_type; $post_type_object = get_post_type_object($post_type); if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || (!isset($_POST['post_ID']) || $post_id != $_POST['post_ID']) || $post_type != 'download' || !check_admin_referer(EDD_POINTS_BASENAME, 'at_edd_points_and_rewards_meta_nonce') || !current_user_can($post_type_object->cap->edit_post, $post_id)) { // Check permission return $post_id; } //check download type is points if (edd_get_download_type($post_id) == 'points') { $_POST['_edd_points_earned'] = '0'; } //update earned points $edd_points_earned = trim($_POST['_edd_points_earned']); $edd_points_earned = !empty($edd_points_earned) ? edd_sanitize_amount($edd_points_earned) : $edd_points_earned; update_post_meta($post_id, '_edd_points_earned', $edd_points_earned); //update maximum discount points $edd_points_max_discount = trim($_POST['_edd_points_max_discount']); $edd_points_max_discount = !empty($edd_points_max_discount) ? edd_sanitize_amount($edd_points_max_discount) : $edd_points_max_discount; update_post_meta($post_id, '_edd_points_max_discount', $edd_points_max_discount); }
/** * Membership length for variable price options * * @since 1.0.0 * @return void */ function edd_slm_price_option_sites_allowed($download_id, $price_id, $args) { if ('bundle' == edd_get_download_type($download_id)) { return; } // Get membership length and unit for variable prices $edd_slm_sites_allowed = edd_slm_get_variable_price_sites_allowed($download_id, $price_id); // Get membership length enabled for deciding when to show membership length option $edd_slm_licensing_enabled = get_post_meta($download_id, '_edd_slm_licensing_enabled', true) ? true : false; $edd_slm_display = $edd_slm_licensing_enabled ? '' : ' style="display:none;"'; ?> <td <?php echo $edd_slm_display; ?> class="edd-slm-sites-allowed edd-slm-variable-toggled-hide"> <input type="number" min="0" step="1" name="edd_variable_prices[<?php echo $price_id; ?> ][edd_slm_sites_allowed]" id="edd_variable_prices[<?php echo $price_id; ?> ][edd_slm_sites_allowed]" size="4" style="width: 70px" value="<?php echo absint($edd_slm_sites_allowed); ?> " /> </td> <?php }