Ejemplo n.º 1
0
/**
 * Show discount field by default
 * If you want a button, simply add <a class="edd-submit button" href="#">Apply discount</a> after the input field.
 * Because the discount is applied when you click outside the field, it will work in the exact same way
*/
function sumobi_edd_show_discount_field()
{
    if (!isset($_GET['payment-mode']) && count(edd_get_enabled_payment_gateways()) > 1 && !edd_is_ajax_enabled()) {
        return;
    }
    // Only show once a payment method has been selected if ajax is disabled
    if (edd_has_active_discounts() && edd_get_cart_total()) {
        ?>
	<fieldset id="edd_discount_code">
		<p>
			<label class="edd-label" for="edd-discount">
				<?php 
        _e('Discount', 'my-child-theme');
        ?>
				<img src="<?php 
        echo EDD_PLUGIN_URL;
        ?>
assets/images/loading.gif" id="edd-discount-loader" style="display:none;"/>
			</label>
			<span class="edd-description"><?php 
        _e('Enter a coupon code if you have one.', 'my-child-theme');
        ?>
</span>
			<input class="edd-input" type="text" id="edd-discount" name="edd-discount" placeholder="<?php 
        _e('Enter discount', 'my-child-theme');
        ?>
"/>
			
		</p>
	</fieldset>
	<?php 
    }
}
/**
 * Hide payment icons when cart total is free
*/
function sumobi_edd_hide_payment_icons()
{
    $cart_total = edd_get_cart_total();
    if ($cart_total) {
        return;
    }
    remove_action('edd_payment_mode_top', 'edd_show_payment_icons');
    remove_action('edd_checkout_form_top', 'edd_show_payment_icons');
}
Ejemplo n.º 3
0
/**
 * Sets an error on checkout if no gateways are enabled
 *
 * @since 1.3.4
 * @return void
 */
function edd_no_gateway_error()
{
    $gateways = edd_get_enabled_payment_gateways();
    if (empty($gateways) && edd_get_cart_total() > 0) {
        edd_set_error('no_gateways', __('You must enable a payment gateway to use Easy Digital Downloads', 'easy-digital-downloads'));
    } else {
        edd_unset_error('no_gateways');
    }
}
function sumobi_edd_force_account_creation_by_cart_total($ret)
{
    // enter the cart total amount that should force account creation
    $limit = 100;
    // get the cart total
    $cart_total = edd_get_cart_total();
    if ($cart_total >= $limit) {
        // if the cart total is greater than or equal to the limit, force account creation
        $ret = (bool) true;
    }
    return $ret;
}
function cl_remove_gateway_fees_by_cart_total($fee)
{
    // enter the cart total for no gateway fees
    $limit = 5;
    // get the cart total
    $cart_total = edd_get_cart_total();
    if ($cart_total >= $limit) {
        // if the cart total is greater than or equal to the limit, remove gateway fees
        return 0;
    } else {
        return $fee;
        // else return the fee we had before
    }
}
/**
 * Process Purchase Form
 *
 * Handles the purchase form process.
 *
 * @access      private
 * @since       1.0
 * @version     1.0.8.1
 * @return      void
 */
function edd_process_purchase_form()
{
    // Make sure the cart isn't empty
    if (!edd_get_cart_contents()) {
        edd_set_error('empty_cart', __('Your cart is empty', 'edd'));
    } else {
        // Validate the form $_POST data
        $valid_data = edd_purchase_form_validate_fields();
        // Allow themes and plugins to hoook to errors
        do_action('edd_checkout_error_checks', $valid_data, $_POST);
    }
    $is_ajax = isset($_POST['edd_ajax']);
    $user = edd_get_purchase_form_user($valid_data);
    if (edd_get_errors() || !$user) {
        if ($is_ajax) {
            do_action('edd_ajax_checkout_errors');
            edd_die();
        } else {
            return false;
        }
    }
    if ($is_ajax) {
        echo 'success';
        edd_die();
    }
    // Setup user information
    $user_info = array('id' => $user['user_id'], 'email' => $user['user_email'], 'first_name' => $user['user_first'], 'last_name' => $user['user_last'], 'discount' => $valid_data['discount']);
    // Setup purchase information
    $purchase_data = array('downloads' => edd_get_cart_contents(), 'fees' => edd_get_cart_fees(), 'subtotal' => edd_get_cart_subtotal(), 'discount' => edd_get_cart_discounted_amount(), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_total(), 'purchase_key' => strtolower(md5(uniqid())), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s'), 'user_info' => $user_info, 'post_data' => $_POST, 'cart_details' => edd_get_cart_content_details(), 'gateway' => $valid_data['gateway'], 'card_info' => $valid_data['cc_info']);
    // Add the user data for hooks
    $valid_data['user'] = $user;
    // Allow themes and plugins to hook before the gateway
    do_action('edd_checkout_before_gateway', $_POST, $user_info, $valid_data);
    // Allow the purchase data to be modified before it is sent to the gateway
    $purchase_data = apply_filters('edd_purchase_data_before_gateway', $purchase_data, $valid_data);
    // If the total amount in the cart is 0, send to the manaul gateway. This emulates a free download purchase
    if (!$purchase_data['price']) {
        // Revert to manual
        $valid_data['gateway'] = 'manual';
    }
    // Used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data.
    edd_set_purchase_session($purchase_data);
    // Send info to the gateway for payment processing
    edd_send_to_gateway($valid_data['gateway'], $purchase_data);
    edd_die();
}
function edd_wallet_process_incentive()
{
    if ($_REQUEST['gateway'] == 'wallet') {
        EDD()->session->set('wallet_has_incentives', '1');
    } else {
        EDD()->session->set('wallet_has_incentives', null);
    }
    // Refresh the cart
    if (empty($_POST['billing_country'])) {
        $_POST['billing_country'] = edd_get_shop_country();
    }
    ob_start();
    edd_checkout_cart();
    $cart = ob_get_clean();
    $response = array('html' => $cart, 'tax_raw' => edd_get_cart_tax(), 'tax' => html_entity_decode(edd_cart_tax(false), ENT_COMPAT, 'UTF-8'), 'tax_rate_raw' => edd_get_tax_rate(), 'tax_rate' => html_entity_decode(edd_get_formatted_tax_rate(), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_cart_total(false), ENT_COMPAT, 'UTF-8'), 'total_raw' => edd_get_cart_total());
    echo json_encode($response);
    edd_die();
}
/**
 * Purchase Form Required Fields
 *
 * @access      private
 * @since       1.5
 * @return      array
 */
function edd_purchase_form_required_fields()
{
    $required_fields = array('edd_email' => array('error_id' => 'invalid_email', 'error_message' => __('Please enter a valid email address', 'easy-digital-downloads')), 'edd_first' => array('error_id' => 'invalid_first_name', 'error_message' => __('Please enter your first name', 'easy-digital-downloads')));
    // Let payment gateways and other extensions determine if address fields should be required
    $require_address = apply_filters('edd_require_billing_address', edd_use_taxes() && edd_get_cart_total());
    if ($require_address) {
        $required_fields['card_zip'] = array('error_id' => 'invalid_zip_code', 'error_message' => __('Please enter your zip / postal code', 'easy-digital-downloads'));
        $required_fields['card_city'] = array('error_id' => 'invalid_city', 'error_message' => __('Please enter your billing city', 'easy-digital-downloads'));
        $required_fields['billing_country'] = array('error_id' => 'invalid_country', 'error_message' => __('Please select your billing country', 'easy-digital-downloads'));
        $required_fields['card_state'] = array('error_id' => 'invalid_state', 'error_message' => __('Please enter billing state / province', 'easy-digital-downloads'));
    }
    return apply_filters('edd_purchase_form_required_fields', $required_fields);
}
/**
 * Validates the supplied discount sent via AJAX.
 *
 * @since 1.0
 * @return void
 */
function edd_ajax_apply_discount()
{
    if (isset($_POST['code']) && check_ajax_referer('edd_checkout_nonce', 'nonce')) {
        $user = isset($_POST['user']) ? $_POST['user'] : $_POST['email'];
        $return = array('msg' => '', 'code' => $_POST['code']);
        if (edd_is_discount_used($_POST['code'], $user)) {
            // Called twice if discount is not used (again by edd_is_discount_valid) but allows for beter usr msg and less execution if discount is used.
            $return['msg'] = __('This discount code has been used already', 'edd');
        } else {
            if (edd_is_discount_valid($_POST['code'], $user)) {
                $discount = edd_get_discount_by_code($_POST['code']);
                $amount = edd_format_discount_rate(edd_get_discount_type($discount->ID), edd_get_discount_amount($discount->ID));
                $discounts = edd_set_cart_discount($_POST['code']);
                $total = edd_get_cart_total($discounts);
                $return = array('msg' => 'valid', 'amount' => $amount, 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'), 'code' => $_POST['code'], 'html' => edd_get_cart_discounts_html($discounts));
            } else {
                $return['msg'] = __('The discount you entered is invalid', 'edd');
            }
        }
        echo json_encode($return);
    }
    edd_die();
}
 /**
  * Maybe show the gateway
  *
  * @access      public
  * @since       1.0.0
  * @param       array $gateways The enabled gateways
  * @return      array $gateways The updated gateways
  */
 public function show_gateway($gateways)
 {
     if (is_user_logged_in() && !is_admin()) {
         // Get the current user
         $user_id = get_current_user_id();
         // Get the wallet value
         $value = edd_wallet()->wallet->balance($user_id);
         // Get the cart total
         $total = edd_get_cart_total();
         // Make sure we aren't making a deposit from our wallet
         $fee = EDD()->fees->get_fee('edd-wallet-deposit');
         if ((double) $value < (double) $total || $fee) {
             unset($gateways['wallet']);
         }
     }
     return $gateways;
 }
Ejemplo n.º 11
0
		<?php 
}
?>

		<tr class="edd_cart_footer_row">
			<?php 
do_action('edd_checkout_table_footer_first');
?>
			<th colspan="<?php 
echo edd_checkout_cart_columns();
?>
" class="edd_cart_total"><?php 
esc_html_e('Total', 'helium');
?>
: <span class="edd_cart_amount" data-subtotal="<?php 
echo edd_get_cart_total();
?>
" data-total="<?php 
echo edd_get_cart_total();
?>
"><?php 
edd_cart_total();
?>
</span></th>
			<?php 
do_action('edd_checkout_table_footer_last');
?>
		</tr>
	</tfoot>
</table>
Ejemplo n.º 12
0
    echo esc_url(url_shop_page());
    ?>
" class="link--naked"><?php 
    _e('&laquo; Continue shopping', 'yoastcom');
    ?>
</a>
				<?php 
}
?>
			</div>
			<div class="three-seventh small-four-fifth"><?php 
_e('Total', 'yoastcom');
?>
</div>
			<div class="one-seventh small-one-fifth edd_cart_total">
				<span class="edd_cart_amount" data-subtotal="<?php 
echo esc_attr(edd_get_cart_total());
?>
" data-total="<?php 
echo esc_attr(edd_get_cart_total());
?>
">
					<?php 
edd_cart_total();
?>
				</span>
			</div>
		</div>
	</div>
</div>
<?php 
/**
 * Recalculate cart taxes
 *
 * @since 1.6
 * @return void
 */
function edd_ajax_recalculate_taxes()
{
    if (!edd_get_cart_contents()) {
        return false;
    }
    if (empty($_POST['billing_country'])) {
        $_POST['billing_country'] = edd_get_shop_country();
    }
    ob_start();
    edd_checkout_cart();
    $cart = ob_get_clean();
    $response = array('html' => $cart, 'tax_raw' => edd_get_cart_tax(), 'tax' => html_entity_decode(edd_cart_tax(false), ENT_COMPAT, 'UTF-8'), 'tax_rate_raw' => edd_get_tax_rate(), 'tax_rate' => html_entity_decode(edd_get_formatted_tax_rate(), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_cart_total(false), ENT_COMPAT, 'UTF-8'), 'total_raw' => edd_get_cart_total());
    echo json_encode($response);
    edd_die();
}
Ejemplo n.º 14
0
 public static function add_edd_cart_js_events()
 {
     $cart_items = edd_get_cart_contents();
     if ($cart_items) {
         foreach ($cart_items as $key => $item) {
             do_action('cio_js_track', 'Product in Cart', array('item_name' => get_the_title($item['id']), 'options' => $item['options'], 'time' => time()));
         }
     }
     do_action('cio_js_track', 'Cart', array('total' => edd_get_cart_total(), 'time' => time()));
 }
				<?php do_action( 'edd_checkout_table_subtotal_last' ); ?>
			</tr>
		<?php endif; ?>

		<tr class="edd_cart_footer_row edd_cart_discount_row" <?php if( ! edd_cart_has_discounts() )  echo ' style="display:none;"'; ?>>
			<?php do_action( 'edd_checkout_table_discount_first' ); ?>
			<th colspan="<?php echo edd_checkout_cart_columns(); ?>" class="edd_cart_discount">
				<?php edd_cart_discounts_html(); ?>
			</th>
			<?php do_action( 'edd_checkout_table_discount_last' ); ?>
		</tr>

		<?php if( edd_use_taxes() ) : ?>
			<tr class="edd_cart_footer_row edd_cart_tax_row"<?php if( ! edd_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
				<?php do_action( 'edd_checkout_table_tax_first' ); ?>
				<th colspan="<?php echo edd_checkout_cart_columns(); ?>" class="edd_cart_tax">
					<?php _e( 'Tax', 'edd' ); ?>:&nbsp;<span class="edd_cart_tax_amount" data-tax="<?php echo edd_get_cart_tax( false ); ?>"><?php echo esc_html( edd_cart_tax() ); ?></span>
				</th>
				<?php do_action( 'edd_checkout_table_tax_last' ); ?>
			</tr>

		<?php endif; ?>

		<tr class="edd_cart_footer_row">
			<?php do_action( 'edd_checkout_table_footer_first' ); ?>
			<th colspan="<?php echo edd_checkout_cart_columns(); ?>" class="edd_cart_total"><?php _e( 'Total', 'edd' ); ?>: <span class="edd_cart_amount" data-subtotal="<?php echo edd_get_cart_total(); ?>" data-total="<?php echo edd_get_cart_total(); ?>"><?php edd_cart_total(); ?></span></th>
			<?php do_action( 'edd_checkout_table_footer_last' ); ?>
		</tr>
	</tfoot>
</table>
Ejemplo n.º 16
0
/**
 * Determines if the gateway menu should be shown
 *
 * If the cart amount is zero, no option is shown and the cart uses the manual gateway
 * to emulate a no-gateway-setup for a free download
 *
 * @since 1.3.2
 * @return bool $show_gateways Whether or not to show the gateways
 */
function edd_show_gateways()
{
    $gateways = edd_get_enabled_payment_gateways();
    $show_gateways = false;
    $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false;
    if (count($gateways) > 1 && empty($chosen_gateway)) {
        $show_gateways = true;
        if (edd_get_cart_total() <= 0) {
            $show_gateways = false;
        }
    }
    return apply_filters('edd_show_gateways', $show_gateways);
}
 /**
  * Outputs checkout tax fields
  */
 public function html_tax_fields()
 {
     if (edd_cart_needs_tax_address_fields() && edd_get_cart_total()) {
         $this->html_default_cc_address();
     }
 }
/**
 * Removes a discount code from the cart via ajax
 *
 * @since 1.7
 * @return void
 */
function edd_ajax_remove_discount()
{
    if (isset($_POST['code'])) {
        edd_unset_cart_discount(urldecode($_POST['code']));
        $total = edd_get_cart_total();
        $return = array('total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'), 'code' => $_POST['code'], 'discounts' => edd_get_cart_discounts(), 'html' => edd_get_cart_discounts_html());
        echo json_encode($return);
    }
    edd_die();
}
/**
 * Get Total Cart Amount
 *
 * Gets the fully formatted total price amount in the cart.
 * uses edd_get_cart_amount().
 *
 * @access public
 * @global $edd_options Array of all the EDD Options
 * @since 1.3.3
 * @return string - the cart amount
 */
function edd_cart_total($echo = true)
{
    global $edd_options;
    $total = apply_filters('edd_cart_total', edd_currency_filter(edd_format_amount(edd_get_cart_total())));
    if (edd_is_cart_taxed()) {
        if (edd_prices_show_tax_on_checkout()) {
            $total .= '<br/><span>' . sprintf(__('(includes %s tax)', 'edd'), edd_cart_tax()) . '</span>';
        }
    }
    if (!$echo) {
        return $total;
    }
    echo $total;
}
 /**
  * Add validation in shmart payment gateway form.
  * @param array   $required_fields All Require fields
  * @return $required_fields
  */
 public function shmart_payment_form_fields_validation($required_fields)
 {
     if ('shmart' == edd_get_chosen_gateway()) {
         $required_fields['contact_number'] = array('error_id' => 'invalid_contact_number', 'error_message' => __('Please enter contact number', 'edd-shmart'));
         if (edd_get_cart_total()) {
             $required_fields['card_address'] = array('error_id' => 'invalid_address', 'error_message' => __('Please enter billing address', 'edd-shmart'));
         }
     }
     return $required_fields;
 }
/**
 * Purchase Form Required Fields
 *
 * @access      private
 * @since       1.5
 * @return      array
 */
function edd_purchase_form_required_fields()
{
    $required_fields = array('edd_email' => array('error_id' => 'invalid_email', 'error_message' => __('Please enter a valid email address', 'easy-digital-downloads')), 'edd_first' => array('error_id' => 'invalid_first_name', 'error_message' => __('Please enter your first name', 'easy-digital-downloads')));
    // Let payment gateways and other extensions determine if address fields should be required
    $require_address = apply_filters('edd_require_billing_address', edd_use_taxes() && edd_get_cart_total());
    if ($require_address) {
        $required_fields['card_zip'] = array('error_id' => 'invalid_zip_code', 'error_message' => __('Please enter your zip / postal code', 'easy-digital-downloads'));
        $required_fields['card_city'] = array('error_id' => 'invalid_city', 'error_message' => __('Please enter your billing city', 'easy-digital-downloads'));
        $required_fields['billing_country'] = array('error_id' => 'invalid_country', 'error_message' => __('Please select your billing country', 'easy-digital-downloads'));
        $required_fields['card_state'] = array('error_id' => 'invalid_state', 'error_message' => __('Please enter billing state / province', 'easy-digital-downloads'));
        // Check if the Customer's Country has been passed in and if it has no states.
        if (isset($_POST['billing_country']) && isset($required_fields['card_state'])) {
            $customer_billing_country = sanitize_text_field($_POST['billing_country']);
            $states = edd_get_shop_states($customer_billing_country);
            // If this country has no states, remove the requirement of a card_state.
            if (empty($states)) {
                unset($required_fields['card_state']);
            }
        }
    }
    return apply_filters('edd_purchase_form_required_fields', $required_fields);
}
if (edd_use_taxes()) {
    ?>
<li class="cart_item edd-cart-meta edd_subtotal" style="display:none;"><?php 
    echo __('Subtotal:', 'edd') . " <span class='subtotal'>" . edd_currency_filter(edd_format_amount(edd_get_cart_subtotal()));
    ?>
</span></li>
<li class="cart_item edd-cart-meta edd_cart_tax" style="display:none;"><?php 
    _e('Estimated Tax:', 'edd');
    ?>
 <span class="cart-tax"><?php 
    echo edd_currency_filter(edd_format_amount(edd_get_cart_tax()));
    ?>
</span></li>
<?php 
}
?>
<li class="cart_item edd-cart-meta edd_total" style="display:none;"><?php 
_e('Total:', 'edd');
?>
 <span class="cart-total"><?php 
echo edd_currency_filter(edd_format_amount(edd_get_cart_total()));
?>
</span></li>
<li class="cart_item edd_checkout" style="display:none;"><a href="<?php 
echo edd_get_checkout_uri();
?>
"><?php 
_e('Checkout', 'edd');
?>
</a></li>
Ejemplo n.º 23
0
/**
 * EDD discount field
*/
function pp_edd_discount_field()
{
    if (isset($_GET['payment-mode']) && edd_is_ajax_disabled()) {
        return;
        // Only show before a payment method has been selected if ajax is disabled
    }
    if (edd_has_active_discounts() && edd_get_cart_total()) {
        $color = edd_get_option('checkout_color', 'blue');
        $color = $color == 'inherit' ? '' : $color;
        $style = edd_get_option('button_style', 'button');
        ?>
		<fieldset id="edd_discount_code">
			
			<p id="edd-show-discount">
				<a href="#" class="edd-discount-link">
					<svg width="32" height="32">
					   <use xlink:href="<?php 
        echo get_stylesheet_directory_uri() . '/images/svg-defs.svg#icon-discount';
        ?>
"></use>
					</svg>
					<?php 
        echo _x('Have a discount code?', 'Entering a discount code', 'edd');
        ?>
				</a>
			</p>

			<p id="edd-discount-code-wrap">
				<label class="edd-label" for="edd-discount">
					<img src="<?php 
        echo EDD_PLUGIN_URL;
        ?>
assets/images/loading.gif" id="edd-discount-loader" style="display:none;"/>
				</label>
				<span class="edd-description"><?php 
        _e('Enter a coupon code if you have one.', 'edd');
        ?>
</span>

				<span class="input-wrap">
					<input class="edd-input" type="text" id="edd-discount" name="edd-discount" placeholder="<?php 
        _e('Enter discount', 'edd');
        ?>
"/>
					<input type="submit" class="edd-apply-discount edd-submit button <?php 
        echo $color . ' ' . $style;
        ?>
" value="<?php 
        echo _x('Apply', 'Apply discount at checkout', 'edd');
        ?>
"/>
				</span>

				
				
				<span id="edd-discount-error-wrap" class="edd_errors" style="display:none;"></span>
			</p>

		</fieldset>
<?php 
    }
}
Ejemplo n.º 24
0
 public function menu_item()
 {
     global $post;
     $menu_item = array('cart_url' => edd_get_checkout_uri(), 'shop_page_url' => get_home_url(), 'cart_contents_count' => edd_get_cart_quantity(), 'cart_total' => edd_currency_filter(edd_format_amount(edd_get_cart_total())));
     return $menu_item;
 }
        /**
         * custom CC form on checkout page
         * 
         * hidden fields retrieve params for Paystack
         *
         * @access public
         */
        public function po_paystack_cc_form()
        {
            global $edd_options;
            $txc = $this->genRefCode();
            $checked = 1;
            $paystack_public = edd_is_test_mode() ? $edd_options['test_public_key'] : $edd_options['live_public_key'];
            ?>
		<input id="txcode" name="txcode" type="hidden" value="<?php 
            echo esc_attr($txc);
            ?>
"/>
		<input id="cptd" name="cptd" type="hidden" value="0" />
		<div id="new_paystack" <?php 
            if ($checked === 1) {
                ?>
style="display:none;"<?php 
            }
            ?>
			data-key="<?php 
            echo esc_attr($paystack_public);
            ?>
"
			data-ref="<?php 
            echo esc_attr($txc);
            ?>
"
			data-amount="<?php 
            echo edd_get_cart_total() * 100;
            ?>
" <?php 
            //Converted to kobo
            ?>
			>
		</div>
		<?php 
        }
Ejemplo n.º 26
0
/**
 * Renders the Purchase button on the Checkout
 *
 * @since 1.2
 * @return string
 */
function edd_checkout_button_purchase()
{
    $color = edd_get_option('checkout_color', 'blue');
    $color = $color == 'inherit' ? '' : $color;
    $style = edd_get_option('button_style', 'button');
    $label = edd_get_option('checkout_label', '');
    if (edd_get_cart_total()) {
        $complete_purchase = !empty($label) ? $label : __('Purchase', 'edd');
    } else {
        $complete_purchase = !empty($label) ? $label : __('Free Download', 'edd');
    }
    ob_start();
    ?>
	<input type="submit" class="edd-submit <?php 
    echo $color;
    ?>
 <?php 
    echo $style;
    ?>
" id="edd-purchase-button" name="edd-purchase" value="<?php 
    echo $complete_purchase;
    ?>
"/>
<?php 
    return apply_filters('edd_checkout_button_purchase', ob_get_clean());
}
 /**
  * Load discount
  *
  * @since 2.0
  */
 public function share_product()
 {
     if (!isset($_POST['product_id'])) {
         return;
     }
     // check nonce
     check_ajax_referer('edd_sd_nonce', 'nonce');
     global $edd_options;
     // get discount code's ID from plugin settings
     $discount = edd_get_option('edd_sd_discount_code', '');
     // get discount code by ID
     $discount = edd_get_discount_code($discount);
     // set cart discount. Discount will only be applied if discount exists.
     $discounts = edd_set_cart_discount($discount);
     $total = edd_get_cart_total($discounts);
     // purchase was shared
     EDD()->session->set('edd_shared', true);
     // store the download ID temporarily
     EDD()->session->set('edd_shared_id', $_POST['product_id']);
     $return = apply_filters('edd_social_discounts_ajax_return', array('msg' => 'valid', 'success_title' => $this->success_title(), 'success_message' => $this->success_message($_POST['product_id']), 'product_id' => $_POST['product_id'], 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'), 'html' => edd_get_cart_discounts_html($discounts)));
     echo json_encode($return);
     edd_die();
 }
/**
 * Get Total Cart Amount
 *
 * Gets the fully formatted total price amount in the cart.
 * uses edd_get_cart_amount().
 *
 * @since 1.3.3
 *
 * @param bool $echo
 * @return mixed|string|void
 */
function edd_cart_total($echo = true)
{
    $total = apply_filters('edd_cart_total', edd_currency_filter(edd_format_amount(edd_get_cart_total())));
    // Todo - Show tax labels here (if needed)
    if (!$echo) {
        return $total;
    }
    echo $total;
}
Ejemplo n.º 29
0
function pw_edd_limit_total_purchase($valid_data, $post_data)
{
    if (edd_get_cart_total() > 100) {
        edd_set_error('too_much', 'You cannot purchase that much at one time.');
    }
}