/** * Discounts short code * * Displays a list of all the active discounts. The active discounts can be configured * from the Discount Codes admin screen. * * @since 1.0.8.2 * @param array $atts Shortcode attributes * @param string $content * @uses edd_get_discounts() * @return string $discounts_lists List of all the active discount codes */ function edd_discounts_shortcode($atts, $content = null) { $discounts = edd_get_discounts(); $discounts_list = '<ul id="edd_discounts_list">'; if (!empty($discounts) && edd_has_active_discounts()) { foreach ($discounts as $discount) { if (edd_is_discount_active($discount->ID)) { $discounts_list .= '<li class="edd_discount">'; $discounts_list .= '<span class="edd_discount_name">' . edd_get_discount_code($discount->ID) . '</span>'; $discounts_list .= '<span class="edd_discount_separator"> - </span>'; $discounts_list .= '<span class="edd_discount_amount">' . edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID)) . '</span>'; $discounts_list .= '</li>'; } } } else { $discounts_list .= '<li class="edd_discount">' . __('No discounts found', 'easy-digital-downloads') . '</li>'; } $discounts_list .= '</ul>'; return $discounts_list; }
/** * Discounts short code * * Displays a list of all the active discounts. The active discounts can be configured * from the Discount Codes admin screen. * * @since 1.0.8.2 * @param array $atts Shortcode attributes * @param string $content * @uses edd_get_discounts() * @return string $discounts_lists List of all the active discount codes */ function edd_discounts_shortcode($atts, $content = null) { $discounts = edd_get_discounts(); if (!$discounts && edd_has_active_discounts()) { return; } $discounts_list = '<ul id="edd_discounts_list">'; foreach ($discounts as $discount) { if (edd_is_discount_active($discount->ID)) { $discounts_list .= '<li class="edd_discount">'; $discounts_list .= '<span class="edd_discount_name">' . edd_get_discount_code($discount->ID) . '</span>'; $discounts_list .= '<span class="edd_discount_separator"> - </span>'; $discounts_list .= '<span class="edd_discount_amount">' . edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID)) . '</span>'; $discounts_list .= '</li>'; } } $discounts_list .= '</ul>'; return $discounts_list; }
/** * Check whether a discount code is valid (when purchasing). * * @since 1.0 * @param string $code Discount Code * @param string $user User info * @return bool */ function edd_is_discount_valid($code = '', $user = '', $set_error = true) { $return = false; $discount_id = edd_get_discount_id_by_code($code); $user = trim($user); if (edd_get_cart_contents()) { if ($discount_id) { if (edd_is_discount_active($discount_id) && edd_is_discount_started($discount_id) && !edd_is_discount_maxed_out($discount_id) && !edd_is_discount_used($code, $user, $discount_id) && edd_discount_is_min_met($discount_id) && edd_discount_product_reqs_met($discount_id)) { $return = true; } } elseif ($set_error) { edd_set_error('edd-discount-error', __('This discount is invalid.', 'edd')); } } return apply_filters('edd_is_discount_valid', $return, $discount_id, $code, $user); }
/** * Is Discount Valid * * Check whether a discount code is valid (when purchasing). * * @access public * @since 1.0 * @return void */ function edd_is_discount_valid($code = '', $email = '') { $return = false; $discount_id = edd_get_discount_id_by_code($code); $email = trim($email); if ($discount_id !== false && $email !== "") { if (edd_is_discount_active($discount_id) && edd_is_discount_started($discount_id) && !edd_is_discount_maxed_out($discount_id) && !edd_is_discount_used($code, $email) && edd_discount_is_min_met($discount_id)) { $return = true; } } return apply_filters('edd_is_discount_valid', $return, $discount_id, $code, $email); }
/** * Check whether a discount code is valid (when purchasing). * * @since 1.0 * @param string $code Discount Code * @param string $user User info * @return bool */ function edd_is_discount_valid($code = '', $user = '') { $return = false; $discount_id = edd_get_discount_id_by_code($code); $user = trim($user); if ($discount_id !== false) { if (edd_is_discount_active($discount_id) && edd_is_discount_started($discount_id) && !edd_is_discount_maxed_out($discount_id) && !edd_is_discount_used($code, $user, $discount_id) && edd_discount_is_min_met($discount_id) && edd_discount_product_reqs_met($discount_id)) { $return = true; } } return apply_filters('edd_is_discount_valid', $return, $discount_id, $code, $user); }
/** * Account * @since 1.0 */ function affwp_account() { ?> <?php $has_ultimate_license = in_array(3, affwp_get_users_price_ids()); $has_professional_license = in_array(2, affwp_get_users_price_ids()); $has_plus_license = in_array(1, affwp_get_users_price_ids()); $has_personal_license = in_array(0, affwp_get_users_price_ids()); /** * Logout message */ if (isset($_GET['logout']) && $_GET['logout'] == 'success') { ?> <p class="alert notice"> <?php _e('You have been successfully logged out', 'affwp'); ?> </p> <?php } ?> <?php // user is not logged in if (!is_user_logged_in()) { ?> <p> <a href="<?php echo site_url('account/affiliates'); ?> ">Looking for our affiliate area?</a> </p> <p> <a href="<?php echo site_url('account/register'); ?> ">Need to register an account?</a> </p> <?php echo edd_login_form(add_query_arg(array('login' => 'success', 'logout' => false), site_url($_SERVER['REQUEST_URI']))); ?> <?php // user is logged in } else { ?> <h2>Professional Add-ons</h2> <?php global $post; /** * Displays the most recent post */ $args = array('posts_per_page' => -1, 'post_type' => 'download', 'tax_query' => array(array('taxonomy' => 'download_category', 'field' => 'slug', 'terms' => 'pro-add-ons'))); $add_ons = new WP_Query($args); ?> <table id="edd-pro-add-ons"> <thead> <tr> <th><?php _e('Name', 'affwp'); ?> </th> <th><?php _e('Version', 'affwp'); ?> </th> <th><?php _e('AffiliateWP version required', 'affwp'); ?> </th> <th><?php _e('Download', 'affwp'); ?> </th> </tr> </thead> <tbody> <?php if (have_posts()) { ?> <?php while ($add_ons->have_posts()) { $add_ons->the_post(); ?> <?php $version = get_post_meta(get_the_ID(), '_edd_sl_version', true); $requires = get_post_meta(get_the_ID(), '_affwp_addon_requires', true); ?> <tr> <td> <?php if (affwp_addon_is_coming_soon(get_the_ID()) && current_user_can('manage_options')) { ?> <a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> <?php } elseif (affwp_addon_is_coming_soon(get_the_ID())) { ?> <?php the_title(); ?> - coming soon <?php } else { ?> <a href="<?php the_permalink(); ?> "><?php the_title(); ?> </a> <?php } ?> </td> <td><?php echo esc_attr($version); ?> </td> <td><?php echo esc_attr($requires); ?> </td> <td> <?php if (edd_get_download_files(get_the_ID())) { ?> <?php if (!($has_ultimate_license || $has_professional_license)) { ?> <?php if (!affwp_addon_is_coming_soon(get_the_ID()) || current_user_can('manage_options')) { ?> <?php if ($has_plus_license || $has_personal_license) { // upgrade ?> <a href="#upgrade" title="Upgrade License" class="popup-content" data-effect="mfp-move-from-bottom">Upgrade license to download</a> <?php } else { // no license ?> <a href="<?php echo site_url('pricing'); ?> ">Purchase ultimate or professional<br/> license to download</a> <?php } ?> <?php } ?> <?php } else { ?> <?php if ($has_ultimate_license || $has_professional_license) { ?> <?php if (!affwp_addon_is_coming_soon(get_the_ID()) || current_user_can('manage_options')) { ?> <a href="<?php echo affwp_get_add_on_download_url(get_the_ID()); ?> ">Download add-on</a> <?php } ?> <?php } ?> <?php } ?> <?php } // edd_get_download_files ?> </td> </tr> <?php } ?> <?php } wp_reset_postdata(); ?> </tbody> </table> <?php affwp_upgrade_license_modal(); ?> <div class="affwp-licenses"> <?php $licenses = affwp_get_users_licenses(); $license_heading = count($licenses) > 1 ? 'Your Licenses' : 'Your license'; ?> <h2><?php echo $license_heading; ?> </h2> <?php // a customer can happily have more than 1 license of any type if ($licenses) { ?> <?php foreach ($licenses as $id => $license) { if ($license['limit'] == 0) { $license['limit'] = 'Unlimited'; } else { $license['limit'] = $license['limit']; } $license_limit_text = $license['limit'] > 1 || $license['limit'] == 'Unlimited' ? ' sites' : ' site'; ?> <div class="affwp-license"> <p><strong><?php echo edd_get_price_option_name(affwp_get_affiliatewp_id(), $license['price_id']); ?> </strong> (<?php echo $license['limit'] . $license_limit_text; ?> ) - <?php echo $license['license']; ?> </p> <?php if (affwp_has_license_expired($license['license'])) { $renewal_link = edd_get_checkout_uri(array('edd_license_key' => $license['license'], 'download_id' => affwp_get_affiliatewp_id())); ?> <p class="license-expired"><a href="<?php echo esc_url($renewal_link); ?> ">Your license has expired. Renew your license now and save 40% →</a></p> <?php } ?> <?php if ($license['price_id'] != 3) { // only provide upgrade if not ultimate ?> <ul> <?php if ($license['price_id'] == 0) { // personal ?> <li><a title="Upgrade to Ultimate license" href="<?php echo affwp_get_license_upgrade_url('ultimate', $id); ?> ">Upgrade to Ultimate license (unlimited sites)</a></li> <li><a title="Upgrade to Professional license" href="<?php echo affwp_get_license_upgrade_url('professional', $id); ?> ">Upgrade to Professional license (unlimited sites)</a></li> <li><a title="Upgrade to Plus license" href="<?php echo affwp_get_license_upgrade_url('plus', $id); ?> ">Upgrade to Plus license (3 sites)</a></li> <?php } ?> <?php if ($license['price_id'] == 1) { // plus ?> <li><a title="Upgrade to Ultimate license" href="<?php echo affwp_get_license_upgrade_url('ultimate', $id); ?> ">Upgrade to Ultimate license (unlimited sites)</a></li> <li><a title="Upgrade to Professional license" href="<?php echo affwp_get_license_upgrade_url('professional', $id); ?> ">Upgrade to Professional license (unlimited sites)</a></li> <?php } ?> <?php if ($license['price_id'] == 2) { // professional ?> <li><a title="Upgrade to Ultimate license" href="<?php echo affwp_get_license_upgrade_url('ultimate', $id); ?> ">Upgrade to Ultimate license (unlimited sites)</a></li> <?php } ?> </ul> <?php } ?> </div> <?php } ?> <?php } else { ?> <p>You do not have a license yet. <a href="<?php echo site_url('pricing'); ?> ">View pricing →</a></p> <?php } ?> </div> <?php // get current user's purchases $purchases = edd_get_users_purchases('', -1); $purchase_ids = array(); $discount_codes = array(); if ($purchases) { $purchase_ids = wp_list_pluck($purchases, 'ID'); } if ($purchase_ids) { foreach ($purchase_ids as $id) { $discount_code = get_post_meta($id, '_edd_purchase_rewards_discount', true); if ($discount_code && edd_is_discount_active($discount_code) && !(function_exists('edd_purchase_rewards') && edd_purchase_rewards()->discounts->discount_code_used($discount_code))) { $discount_codes[] = edd_get_discount_code($discount_code); } } } ?> <?php if ($discount_codes) { ?> <h2>Available Discount Codes</h2> <p>Click a discount below and it will be applied to checkout.</p> <ul class="edd-pr-discounts"> <?php foreach ($discount_codes as $code) { ?> <li> <a href="<?php echo add_query_arg('discount', $code, site_url('/account/')); ?> "> <?php echo $code; ?> </a> </li> <?php } ?> </ul> <?php } ?> <?php // purchase history echo '<h2>' . __('Purchase History', 'affwp') . '</h2>'; echo edd_purchase_history(); // download history echo '<h2>' . __('Download History', 'affwp') . '</h2>'; echo edd_download_history(); // profile editor echo '<h2>' . __('Edit your profile', 'affwp') . '</h2>'; echo do_shortcode('[edd_profile_editor]'); ?> <?php } ?> <?php }
/** * Discounts Page * * Renders the discount page contents. * * @access private * @since 1.0 * @return void */ function edd_discounts_page() { global $edd_options; $current_page = get_bloginfo('wpurl') . '/wp-admin/admin.php?edit.php?post_type=download&page=edd-discounts'; ?> <div class="wrap"> <?php if (isset($_GET['edd-action']) && $_GET['edd-action'] == 'edit_discount') { ?> <?php include_once EDD_PLUGIN_DIR . 'includes/admin-pages/forms/edit-discount.php'; ?> <?php } else { ?> <h2><?php _e('Discount Codes', 'edd'); ?> </h2> <?php $discounts = edd_get_discounts(); ?> <table class="wp-list-table widefat fixed posts edd-discounts"> <thead> <tr> <th><?php _e('Name', 'edd'); ?> </th> <th><?php _e('Code', 'edd'); ?> </th> <th><?php _e('Amount', 'edd'); ?> </th> <th><?php _e('Uses', 'edd'); ?> </th> <th><?php _e('Max Uses', 'edd'); ?> </th> <th><?php _e('Start Date', 'edd'); ?> </th> <th><?php _e('Expiration', 'edd'); ?> </th> <th><?php _e('Status', 'edd'); ?> </th> <th><?php _e('Actions', 'edd'); ?> </th> </tr> </thead> <tfoot> <tr> <th><?php _e('Name', 'edd'); ?> </th> <th><?php _e('Code', 'edd'); ?> </th> <th><?php _e('Amount', 'edd'); ?> </th> <th><?php _e('Uses', 'edd'); ?> </th> <th><?php _e('Max Uses', 'edd'); ?> </th> <th><?php _e('Start Date', 'edd'); ?> </th> <th><?php _e('Expiration', 'edd'); ?> </th> <th><?php _e('Status', 'edd'); ?> </th> <th><?php _e('Actions', 'edd'); ?> </th> </tr> </tfoot> <tbody> <?php if ($discounts) { ?> <?php foreach ($discounts as $discount_key => $discount) { ?> <tr> <td><?php if (isset($discount['name'])) { echo $discount['name']; } ?> </td> <td><?php if (isset($discount['code'])) { echo $discount['code']; } ?> </td> <td><?php if (isset($discount['amount'])) { echo edd_format_discount_rate($discount['type'], $discount['amount']); } ?> </td> <td> <?php if (isset($discount['uses']) && isset($discount['max']) && $discount['uses'] != '' && $discount['max'] != '') { echo $discount['uses'] == '' ? 0 : $discount['uses'] . '/' . $discount['max']; } else { echo isset($discount['uses']) ? $discount['uses'] : 0; } ?> </td> <td> <?php if (isset($discount['max'])) { echo $discount['max'] == '' ? __('unlimited', 'edd') : $discount['max']; } else { _e('unlimited', 'edd'); } ?> </td> <td> <?php if (isset($discount['start']) && $discount['start'] != '') { echo date(get_option('date_format'), strtotime($discount['start'])); } else { _e('No start date', 'edd'); } ?> </td> <td> <?php if (isset($discount['expiration']) && $discount['expiration'] != '') { echo edd_is_discount_expired($discount_key) ? __('Expired', 'edd') : $discount['expiration']; } else { _e('no expiration', 'edd'); } ?> </td> <td><?php if (isset($discount['status'])) { echo $discount['status']; } ?> </td> <td> <a href="<?php echo add_query_arg('edd-action', 'edit_discount', add_query_arg('discount', $discount_key, $current_page)); ?> "><?php _e('Edit', 'edd'); ?> </a> | <?php if (edd_is_discount_active($discount_key)) { ?> <a href="<?php echo add_query_arg('edd-action', 'deactivate_discount', add_query_arg('discount', $discount_key, $current_page)); ?> "><?php _e('Deactivate', 'edd'); ?> </a> | <?php } else { ?> <a href="<?php echo add_query_arg('edd-action', 'activate_discount', add_query_arg('discount', $discount_key, $current_page)); ?> "><?php _e('Activate', 'edd'); ?> </a> | <?php } ?> <a href="<?php echo add_query_arg('edd-action', 'delete_discount', add_query_arg('discount', $discount_key, $current_page)); ?> "><?php _e('Delete', 'edd'); ?> </a> </td> </tr> <?php } ?> <?php } else { ?> <tr><td colspan=10><?php _e('No discount codes have been created.', 'edd'); ?> </td> <?php } ?> </tbody> </table> <?php do_action('edd_discounts_below_table'); ?> <?php include_once EDD_PLUGIN_DIR . 'includes/admin-pages/forms/add-discount.php'; ?> <?php } ?> </div><!--end wrap--> <?php }