/** * Render the download information meta box * * @since 1.0 */ function edd_sl_render_license_upgrade_paths_meta_box() { global $post; $enabled = get_post_meta($post->ID, '_edd_sl_enabled', true) ? true : false; $paths = edd_sl_get_upgrade_paths($post->ID); ?> <div id="edd_sl_upgrade_paths_wrapper" class="edd_meta_table_wrap"> <table class="widefat edd_repeatable_table" width="100%" cellpadding="0" cellspacing="0"> <thead> <tr> <th class="sl-upgrade-download"><?php echo edd_get_label_singular(); ?> </th> <th class="sl-upgrade-price-option"><?php _e('Price Option', 'edd_sl'); ?> </th> <th class="sl-upgrade-prorate"><?php _e('Prorate', 'edd_sl'); ?> </th> <th class="sl-upgrade-discount"><?php _e('Additional Discount', 'edd_sl'); ?> </th> <th class="sl-upgrade-remove"></th> </tr> </thead> <tbody> <?php if (!empty($paths) && is_array($paths)) { foreach ($paths as $key => $value) { ?> <tr class="edd_repeatable_upload_wrapper edd_repeatable_row" data-key="<?php echo esc_attr($key); ?> "> <td> <?php echo EDD()->html->product_dropdown(array('name' => 'edd_sl_upgrade_paths[' . $key . '][download_id]', 'id' => 'edd_sl_upgrade_paths', 'selected' => $value['download_id'], 'multiple' => false, 'chosen' => true, 'class' => 'edd-sl-upgrade-path-download')); ?> </td> <td class="pricing"> <?php if (edd_has_variable_prices($value['download_id'])) { $options = array(); $prices = edd_get_variable_prices($value['download_id']); if (!empty($prices)) { foreach ($prices as $price_key => $price) { $options[$price_key] = $prices[$price_key]['name']; } } echo EDD()->html->select(array('name' => 'edd_sl_upgrade_paths[' . $key . '][price_id]', 'options' => $options, 'selected' => $value['price_id'], 'show_option_none' => false, 'show_option_all' => false, 'class' => 'edd-sl-upgrade-path-price-id')); } else { _e('N/A', 'edd_sl'); } ?> </td> <td class="sl-upgrade-prorate"> <?php echo EDD()->html->checkbox(array('name' => 'edd_sl_upgrade_paths[' . $key . '][pro_rated]', 'value' => '1', 'current' => !empty($value['pro_rated']) ? 1 : 0)); ?> </td> <td> <?php echo EDD()->html->text(array('name' => 'edd_sl_upgrade_paths[' . $key . '][discount]', 'value' => esc_attr($value['discount']), 'placeholder' => __('Amount', 'edd'), 'class' => 'edd-price-field')); ?> </td> <td> <a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php echo admin_url('/images/xit.gif'); ?> ) no-repeat;">×</a> </td> </tr> <?php } } else { ?> <tr class="edd_repeatable_upload_wrapper edd_repeatable_row"> <td> <?php echo EDD()->html->product_dropdown(array('name' => 'edd_sl_upgrade_paths[1][download_id]', 'id' => 'edd_sl_upgrade_paths', 'selected' => !empty($post->status) ? $post->ID : false, 'multiple' => false, 'chosen' => true, 'class' => 'edd-sl-upgrade-path-download')); ?> </td> <td class="pricing"> <?php if (edd_has_variable_prices($post->ID)) { ?> <?php $options = array(); $prices = edd_get_variable_prices($post->ID); if (!empty($prices)) { foreach ($prices as $price_key => $price) { $options[$price_key] = $prices[$price_key]['name']; } } echo EDD()->html->select(array('name' => 'edd_sl_upgrade_paths[1][price_id]', 'options' => $options, 'show_option_none' => false, 'show_option_all' => false, 'class' => 'edd-sl-upgrade-path-price-id')); ?> <?php } else { ?> <?php _e('N/A', 'edd_sl'); ?> <?php } ?> </td> <td class="sl-upgrade-prorate"> <?php echo EDD()->html->checkbox(array('name' => 'edd_sl_upgrade_paths[1][pro_rated]', 'value' => '1')); ?> </td> <td> <?php echo EDD()->html->text(array('name' => 'edd_sl_upgrade_paths[1][discount]', 'placeholder' => __('Amount', 'edd'), 'class' => 'edd-price-field')); ?> </td> <td> <a href="#" class="edd_remove_repeatable" data-type="file" style="background: url(<?php echo admin_url('/images/xit.gif'); ?> ) no-repeat;">×</a> </td> </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 Upgrade Path', 'edd'); ?> </a> </td> </tr> </tbody> </table> </div> <p class="description"><?php _e('Configure the optional upgrade paths for customers. ', 'edd_sl'); ?> </p> <?php }
/** * 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); }
/** * Add the license upgrade from trial to the cart * * @param int $license_id * * @return string */ protected static function prepare_upgrade($license_id) { $download_id = \EDD_Software_Licensing::instance()->get_download_id($license_id); if (is_numeric($download_id)) { $upgrades = edd_sl_get_upgrade_paths($download_id); if (is_array($upgrades) && !empty($upgrades)) { reset($upgrades); $upgrade_price_id = key($upgrades); $upgrade = edd_sl_get_upgrade_path(ids::$trial_id, $upgrade_price_id); $options = array('price_id' => $upgrade['price_id'], 'is_upgrade' => true, 'upgrade_id' => $upgrade_price_id, 'license_id' => $license_id, 'cost' => edd_sl_get_license_upgrade_cost($license_id, $upgrade_price_id)); $added = edd_add_to_cart($upgrade['download_id'], $options); return $added; } } }