/**
 * Show cart link and quantity count in header if the cart has contents.
 *
 * The ".edd-cart-quantity" class is needed in order for the quantity to be
 * updated dynamically via AJAX.
 *
 * @todo  Add cart link to mobile navigation bar.
 *
 * @since 1.0.0
 */
function huesos_edd_show_header_cart_link()
{
    if (!edd_get_cart_contents()) {
        return;
    }
    printf('<p class="cart-quantity"><a class="button" href="%1$s">%2$s (<span class="edd-cart-quantity">%3$s</span>)</a></p>', esc_url(edd_get_checkout_uri()), esc_html__('Cart', 'huesos'), esc_html(edd_get_cart_quantity()));
}
 public function validate_fields($valid_data, $post_data)
 {
     global $rcp_gifts;
     if (!$this->cart_has_gift_product()) {
         return;
     }
     $items = edd_get_cart_contents();
     $gifts = $_POST['edd_rcp_gift'];
     foreach ($items as $key => $item) {
         if (!$rcp_gifts->is_gift_product($item['id'])) {
             continue;
         }
         $email = $gifts[$key]['email'] ? sanitize_text_field($gifts[$key]['email']) : false;
         $name = $gifts[$key]['name'] ? sanitize_text_field($gifts[$key]['name']) : false;
         if (empty($email)) {
             edd_set_error('empty_gift_email_' . $key, __('Please enter an email address for the gift recipient', 'rcp-gifts'));
         }
         if (empty($name)) {
             edd_set_error('empty_gift_name_' . $key, __('Please enter the recipient\'s name', 'rcp-gifts'));
         }
         if (!is_email($email)) {
             edd_set_error('invalid_gift_email_' . $key, __('Please enter a valid email address for the gift recipient', 'rcp-gifts'));
         }
     }
 }
/**
 * Get Checkout Form
 *
 * @access      private
 * @since       1.0
 * @return      string
*/
function edd_checkout_form()
{
    global $edd_options, $user_ID, $post;
    ob_start();
    ?>

		<?php 
    if (edd_get_cart_contents()) {
        ?>

			<?php 
        edd_checkout_cart();
        ?>

			<div id="edd_checkout_form_wrap" class="edd_clearfix">

				<?php 
        do_action('edd_checkout_form_top');
        if (edd_show_gateways()) {
            do_action('edd_payment_payment_mode_select');
        } else {
            do_action('edd_purchase_form');
        }
        do_action('edd_checkout_form_bottom');
        ?>
			</div><!--end #edd_checkout_form_wrap-->
		<?php 
    } else {
        do_action('edd_empty_cart');
    }
    return ob_get_clean();
}
/**
 * Shopping Cart
 *
 * @access      public
 * @since       1.0 
 * @return      string
*/
function edd_shopping_cart($echo = false)
{
    global $edd_options;
    ob_start();
    ?>
	
	<?php 
    do_action('edd_before_cart');
    ?>
	<ul class="edd-cart">
	<?php 
    $cart_items = edd_get_cart_contents();
    if ($cart_items) {
        foreach ($cart_items as $key => $item) {
            echo edd_get_cart_item_template($key, $item, false);
        }
        echo '<li class="cart_item edd_checkout"><a href="' . get_permalink($edd_options['purchase_page']) . '">' . __('Checkout', 'edd') . '</a></li>';
    } else {
        echo '<li class="cart_item empty">' . edd_empty_cart_message() . '</li>';
        echo '<li class="cart_item edd_checkout" style="display:none;"><a href="' . get_permalink($edd_options['purchase_page']) . '">' . __('Checkout', 'edd') . '</a></li>';
    }
    ?>
	</ul>
	<?php 
    do_action('edd_after_cart');
    ?>
	<?php 
    if ($echo) {
        echo ob_get_clean();
    } else {
        return ob_get_clean();
    }
}
/**
 * Process Purchase Form
 *
 * Handles the purchase form process.
 *
 * @access      private
 * @since       1.0
 * @return      void
 */
function edd_process_purchase_form()
{
    do_action('edd_pre_process_purchase');
    // Make sure the cart isn't empty
    if (!edd_get_cart_contents() && !edd_cart_has_fees()) {
        $valid_data = false;
        edd_set_error('empty_cart', __('Your cart is empty', 'easy-digital-downloads'));
    } else {
        // Validate the form $_POST data
        $valid_data = edd_purchase_form_validate_fields();
        // Allow themes and plugins to hook to errors
        do_action('edd_checkout_error_checks', $valid_data, $_POST);
    }
    $is_ajax = isset($_POST['edd_ajax']);
    // Process the login form
    if (isset($_POST['edd_login_submit'])) {
        edd_process_purchase_login();
    }
    // Validate the user
    $user = edd_get_purchase_form_user($valid_data);
    if (false === $valid_data || 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'], 'address' => $user['address']);
    $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
    // 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($user['user_email'] . date('Y-m-d H:i:s') . $auth_key . uniqid('edd', true))), 'user_email' => $user['user_email'], 'date' => date('Y-m-d H:i:s', current_time('timestamp')), 'user_info' => stripslashes_deep($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);
    // If the total amount in the cart is 0, send to the manual gateway. This emulates a free download purchase
    if (!$purchase_data['price']) {
        // Revert to manual
        $purchase_data['gateway'] = 'manual';
        $_POST['edd-gateway'] = 'manual';
    }
    // 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);
    // Setup the data we're storing in the purchase session
    $session_data = $purchase_data;
    // Make sure credit card numbers are never stored in sessions
    unset($session_data['card_info']['card_number']);
    // Used for showing download links to non logged-in users after purchase, and for other plugins needing purchase data.
    edd_set_purchase_session($session_data);
    // Send info to the gateway for payment processing
    edd_send_to_gateway($purchase_data['gateway'], $purchase_data);
    edd_die();
}
function download_checkout_count_function($atts, $content)
{
    $cart_items = edd_get_cart_contents();
    if (empty($cart_items)) {
        return 0;
    } else {
        return count($cart_items);
    }
}
/**
 * Prevents logged-in customers from purchasing an item twice
 *
 */
function pw_edd_prevent_duplicate_purchase($valid_data, $posted)
{
    $cart_contents = edd_get_cart_contents();
    foreach ($cart_contents as $item) {
        if (edd_has_user_purchased(get_current_user_id(), $item['id'])) {
            edd_set_error('duplicate_item', 'You have already purchased this item so may not purchase it again');
        }
    }
}
 public function empty_cart($wp_admin_bar)
 {
     $title = __('Empty Cart', 'edd-dev-tools');
     $count = count(edd_get_cart_contents());
     if (!empty($count)) {
         $title .= '(' . $count . ')';
     }
     $args = array('id' => 'edd_empty_cart', 'title' => $title, 'href' => add_query_arg('empty_cart', true));
     $wp_admin_bar->add_node($args);
 }
/**
 * Get Checkout Form
 *
 * @since 1.0
 * @return string
 */
function edd_checkout_form()
{
    $payment_mode = edd_get_chosen_gateway();
    $form_action = esc_url(edd_get_checkout_uri('payment-mode=' . $payment_mode));
    ob_start();
    echo '<div id="edd_checkout_wrap">';
    if (edd_get_cart_contents() || edd_cart_has_fees()) {
        edd_checkout_cart();
        ?>
			<div id="edd_checkout_form_wrap" class="edd_clearfix">
				<?php 
        do_action('edd_before_purchase_form');
        ?>
				<form id="edd_purchase_form" class="edd_form" action="<?php 
        echo $form_action;
        ?>
" method="POST">
					<?php 
        /**
         * Hooks in at the top of the checkout form
         *
         * @since 1.0
         */
        do_action('edd_checkout_form_top');
        if (edd_show_gateways()) {
            do_action('edd_payment_mode_select');
        } else {
            do_action('edd_purchase_form');
        }
        /**
         * Hooks in at the bottom of the checkout form
         *
         * @since 1.0
         */
        do_action('edd_checkout_form_bottom');
        ?>
				</form>
				<?php 
        do_action('edd_after_purchase_form');
        ?>
			</div><!--end #edd_checkout_form_wrap-->
		<?php 
    } else {
        /**
         * Fires off when there is nothing in the cart
         *
         * @since 1.0
         */
        do_action('edd_cart_empty');
    }
    echo '</div><!--end #edd_checkout_wrap-->';
    return ob_get_clean();
}
/**
 * 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()
{
    // no need to run on admin
    if (is_admin()) {
        return;
    }
    // verify the nonce for this action
    if (!isset($_POST['edd-nonce']) || !wp_verify_nonce($_POST['edd-nonce'], 'edd-purchase-nonce')) {
        return;
    }
    // make sure the cart isn't empty
    $cart = edd_get_cart_contents();
    if (empty($cart)) {
        wp_die(sprintf(__('Your cart is empty, please return to the %ssite%s and try again.', 'edd'), '<a href="' . esc_url(home_url()) . '" title="' . get_bloginfo('name') . '">', '</a>'), __('Error', 'edd'));
    }
    // 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', $_POST);
    // check errors
    if (false !== ($errors = edd_get_errors())) {
        // we have errors, send back to checkout
        edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']);
        exit;
    }
    // check user
    if (false === ($user = edd_get_purchase_form_user($valid_data))) {
        // something went wrong when collecting data, send back to checkout
        edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']);
        exit;
    }
    // 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(), 'subtotal' => edd_get_cart_amount(false), 'tax' => edd_get_cart_tax(), 'price' => edd_get_cart_amount(), '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'] <= 0) {
        // 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);
    exit;
}
function pw_edd_recurring_limit_one_subscription($valid_data, $post_data)
{
    if (!class_exists('EDD_Recurring_Customer')) {
        return;
    }
    if (!is_user_logged_in()) {
        return;
    }
    $purchase_data = array('downloads' => edd_get_cart_contents());
    if (EDD_Recurring_Customer::is_customer_active() && EDD_Recurring()->is_purchase_recurring($purchase_data)) {
        edd_set_error('edd-one-subscription', __('You already have an active subscription so may not purchase a second one.', 'edd'));
    }
}
/**
 * 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()
{
    global $edd_options;
    // no need to run on admin
    if (is_admin()) {
        return;
    }
    // verify the nonce for this action
    if (!isset($_POST['edd-nonce']) || !wp_verify_nonce($_POST['edd-nonce'], 'edd-purchase-nonce')) {
        return;
    }
    // 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', $_POST);
    // check errors
    if (false !== ($errors = edd_get_errors())) {
        // we have errors, send back to checkout
        edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']);
        exit;
    }
    // check user
    if (false === ($user = edd_get_purchase_form_user($valid_data))) {
        // something went wrong when collecting data, send back to checkout
        edd_send_back_to_checkout('?payment-mode=' . $valid_data['gateway']);
        exit;
    }
    // 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(), 'price' => edd_get_cart_amount(), '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'] <= 0) {
        // revert to manual
        $valid_data['gateway'] = 'manual';
    }
    if (isset($edd_options['show_links_on_success'])) {
        // used for showing download links to non logged-in users after purchase
        edd_set_purchase_session($purchase_data);
    }
    // send info to the gateway for payment processing
    edd_send_to_gateway($valid_data['gateway'], $purchase_data);
    exit;
}
/**
 * Do any items in the cart require shipping?
 *
 * @since Astoundify Crowdfunding 0.9
 *
 * @return void
 */
function atcf_shipping_cart_shipping()
{
    $cart_items = edd_get_cart_contents();
    $needs = false;
    if (!empty($cart_items)) {
        foreach ($cart_items as $key => $item) {
            $campaign = atcf_get_campaign($item['id']);
            if ($campaign->needs_shipping()) {
                $needs = true;
            }
        }
    }
    return apply_filters('atcf_shipping_cart_shipping', $needs);
}
/**
 * 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();
}
Beispiel #15
0
/**
 * Add our own output of recommended products, as the plugin
 * uses the standard grid by default, and we need our own.
 *
 * @since Marketify 1.0
 *
 * @return void
 */
function marketify_recommended_products()
{
    global $edd_options;
    if (!function_exists('edd_rp_get_suggestions')) {
        return;
    }
    if (is_singular('download')) {
        global $post;
        $suggestion_data = edd_rp_get_suggestions($post->ID);
    } else {
        $cart_items = edd_get_cart_contents();
        if (empty($cart_items)) {
            return;
        }
        $post_ids = wp_list_pluck($cart_items, 'id');
        $user_id = is_user_logged_in() ? get_current_user_id() : false;
        $suggestion_data = edd_rp_get_multi_suggestions($post_ids, $user_id);
    }
    if (!is_array($suggestion_data) || empty($suggestion_data)) {
        return;
    }
    $suggestions = array_keys($suggestion_data);
    $suggested_downloads = new WP_Query(array('post__in' => $suggestions, 'post_type' => 'download', 'posts_per_page' => edd_get_option('edd_rp_suggestion_count')));
    ?>

	<h1 class="section-title recommended-products"><span><?php 
    _e('Recommended Products', 'marketify');
    ?>
</span></h1>

	<div class="row edd-recommended-products">
		<?php 
    while ($suggested_downloads->have_posts()) {
        $suggested_downloads->the_post();
        ?>
		<div class="col-lg-3 col-md-4 col-sm-6">
			<?php 
        get_template_part('content-grid', 'download');
        ?>
		</div>
		<?php 
    }
    ?>
	</div>
<?php 
}
/**
 * Get Checkout Form
 *
 * @since 1.0
 * @global $edd_options Array of all the EDD options
 * @global $user_ID ID of current logged in user
 * @global $post Current Post Object
 * @return string
 */
function edd_checkout_form()
{
    global $edd_options, $user_ID, $post;
    $payment_mode = edd_get_chosen_gateway();
    $form_action = esc_url(edd_get_checkout_uri('payment-mode=' . $payment_mode));
    ob_start();
    echo '<div id="edd_checkout_wrap">';
    if (edd_get_cart_contents() || edd_cart_has_fees()) {
        edd_checkout_cart();
        ?>
			<div id="edd_checkout_form_wrap" class="edd_clearfix">
				<?php 
        do_action('edd_before_purchase_form');
        ?>
				<form id="edd_purchase_form" class="edd_form" action="<?php 
        echo $form_action;
        ?>
" method="POST">
					<?php 
        do_action('edd_checkout_form_top');
        if (edd_show_gateways()) {
            do_action('edd_payment_mode_select');
        } else {
            do_action('edd_purchase_form');
        }
        do_action('edd_checkout_form_bottom');
        ?>
				</form>
				<?php 
        do_action('edd_after_purchase_form');
        ?>
			</div><!--end #edd_checkout_form_wrap-->
		<?php 
    } else {
        do_action('edd_cart_empty');
    }
    echo '</div><!--end #edd_checkout_wrap-->';
    return ob_get_clean();
}
 /**
  * Add Menu Cart to menu
  * 
  * @return menu items including cart
  */
 public function submenu_items()
 {
     global $post;
     $get_cart = edd_get_cart_contents();
     $submenu_items = '';
     if (edd_get_cart_contents() > 0) {
         foreach ($get_cart as $key => $item) {
             //$_product = $item['data'];
             if (count($get_cart) > 0) {
                 $item_thumbnail = get_the_post_thumbnail($item['id'], apply_filters('edd_checkout_image_size', array(25, 25)));
                 $item_name = get_the_title($item['id']);
                 $item_quantity = '1';
                 $item_price = edd_cart_item_price($item['id'], $item['options']);
                 // Item permalink if product visible
                 $item_permalink = esc_url(get_permalink($item['id']));
                 $submenu_items[] = array('item_thumbnail' => $item_thumbnail, 'item_name' => $item_name, 'item_quantity' => $item_quantity, 'item_price' => $item_price, 'item_permalink' => $item_permalink);
             }
         }
     } else {
         $submenu_items = '';
     }
     return $submenu_items;
 }
function sumobi_edd_force_account_creation_by_download_category_or_tag($ret)
{
    // download categories that the download must belong to before account creation is forced
    $categories_to_search = array('cat1', 'cat2', 'cat3');
    // download tags that the download must belong to before account creation is forced
    $tags_to_search = array('tag1', 'tag2');
    // get our cart contents
    $cart = edd_get_cart_contents();
    if ($cart) {
        // create an array with all our download IDs
        $download_ids = wp_list_pluck($cart, 'id');
        if ($download_ids) {
            // loop through IDs and check if they belong to any of the categories or tags
            foreach ($download_ids as $id) {
                if (has_term($categories_to_search, 'download_category', $id) || has_term($tags_to_search, 'download_tag', $id)) {
                    // found one, force account creation
                    $ret = (bool) true;
                }
            }
        }
    }
    return $ret;
}
Beispiel #19
0
 /**
  * Gets the total number of tickets requested *per event* (of course, we're only
  * interested in events that maintain global stock where tickets for those events
  * that utilize global stock are in the cart).
  *
  * @return array
  */
 protected function cart_get_global_stock_quantities()
 {
     $edd_tickets = Tribe__Tickets_Plus__Commerce__EDD__Main::get_instance();
     $quantities = array();
     foreach ((array) edd_get_cart_contents() as $cart_item) {
         $product = get_post($cart_item['id']);
         $event = $edd_tickets->get_event_for_ticket($product->ID);
         // Skip if we are not looking at an event ticket
         if (!$event) {
             continue;
         }
         $global_stock = new Tribe__Tickets__Global_Stock($event->ID);
         // Skip if the ticket does not use global stock
         if (!$global_stock->is_enabled()) {
             continue;
         }
         $tickets = $this->get_event_tickets($event->ID);
         if (!isset($tickets[$product->ID])) {
             continue;
         }
         // We only need to accumulate the stock quantities of tickets using *global* stock
         if (Tribe__Tickets__Global_Stock::OWN_STOCK_MODE === $tickets[$product->ID]->global_stock_mode()) {
             continue;
         }
         // This is also a great opportunity to test and see if ticket caps have been exceeded
         if (Tribe__Tickets__Global_Stock::CAPPED_STOCK_MODE === $tickets[$product->ID]->global_stock_mode()) {
             if ($cart_item['quantity'] > $tickets[$product->ID]->global_stock_cap()) {
                 $this->cart_flag_capped_stock_error($product->ID);
             }
         }
         if (!isset($quantities[$event->ID])) {
             $quantities[$event->ID] = 0;
         }
         $quantities[$event->ID] += $cart_item['quantity'];
     }
     return $quantities;
 }
/**
 * Renders the Shopping Cart
 *
 * @since 1.0
 * @return string Fully formatted cart
*/
function edd_shopping_cart($echo = false)
{
    global $edd_options;
    ob_start();
    do_action('edd_before_cart');
    $display = 'style="display:none;"';
    $cart_quantity = edd_get_cart_quantity();
    if ($cart_quantity > 0) {
        $display = "";
    }
    echo "<p class='edd-cart-number-of-items' {$display}>" . __('Number of items in cart', 'edd') . ': <span class="edd-cart-quantity">' . $cart_quantity . '<span></p>';
    ?>

	<ul class="edd-cart">
	<!--dynamic-cached-content-->
	<?php 
    $cart_items = edd_get_cart_contents();
    if ($cart_items) {
        foreach ($cart_items as $key => $item) {
            echo edd_get_cart_item_template($key, $item, false);
        }
        edd_get_template_part('widget', 'cart-checkout');
    } else {
        edd_get_template_part('widget', 'cart-empty');
    }
    ?>
	<!--/dynamic-cached-content-->
	</ul>
	<?php 
    do_action('edd_after_cart');
    if ($echo) {
        echo ob_get_clean();
    } else {
        return ob_get_clean();
    }
}
 /**
  * Calculate Maximum Possible discount available
  *
  * Handles to calculate maximum possible discount
  * 
  * @package Easy Digital Downloads - Points and Rewards
  * @since 1.0.0
  **/
 public function edd_points_get_discount_for_redeeming_points()
 {
     global $edd_options;
     //get users points
     $available_user_disc = $this->edd_points_get_userpoints_value();
     //get cart subtotal
     $cartsubtotal = edd_get_cart_subtotal() - edd_get_cart_discounted_amount();
     //check price is include tas or not
     if (edd_prices_include_tax() == 'yes') {
         $cartsubtotal = $cartsubtotal - edd_get_cart_tax();
     }
     //check user has points or not
     if (empty($available_user_disc)) {
         return 0;
     }
     //get cart content
     $cartdata = edd_get_cart_contents();
     $discount_applied = 0;
     // calculate the discount to be applied by iterating through each item in the cart and calculating the individual
     // maximum discount available
     foreach ($cartdata as $item_key => $item) {
         //max discount
         $max_discount = $this->edd_points_get_max_points_discount_for_download($item['id']);
         //check item of options set then consider that
         if (isset($item['options'])) {
             $itemoptions = $item['options'];
         } elseif (isset($item['item_number']['options'])) {
             $itemoptions = $item['item_number']['options'];
         } else {
             $itemoptions = array();
         }
         //get download price
         $downloadprice = edd_get_cart_item_price($item['id'], $itemoptions);
         if (is_numeric($max_discount)) {
             // adjust the max discount by the quantity being ordered
             $max_discount *= $item['quantity'];
             // if the discount available is greater than the max discount, apply the max discount
             $discount = $available_user_disc <= $max_discount ? $available_user_disc : $max_discount;
         } else {
             //when maximum discount is not set for product then allow maximum total cost of product as a discount
             $max_price_discount = $downloadprice * $item['quantity'];
             // if the discount available is greater than the max discount, apply the max discount
             $discount = $available_user_disc <= $max_price_discount ? $available_user_disc : $max_price_discount;
         }
         // add the discount to the amount to be applied
         $discount_applied += $discount;
         // reduce the remaining discount available to be applied
         $available_user_disc -= $discount;
     }
     //end for loop
     // if the available discount is greater than the order total, make the discount equal to the order total less any other discounts
     $discount_applied = max(0, min($discount_applied, $cartsubtotal));
     //$discount_applied = max( 0, $discount_applied );
     // limit the discount available by the global maximum discount if set
     $max_discount = $edd_options['edd_points_cart_max_discount'];
     if ($max_discount && $max_discount < $discount_applied) {
         $discount_applied = $max_discount;
     }
     return $discount_applied;
 }
/**
 * 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);
}
 /**
  * Apply the shipping fees to the cart
  *
  * @since 1.0
  *
  * @access private
  * @return void
  */
 public function apply_shipping_fees()
 {
     $this->remove_shipping_fees();
     if (!$this->cart_needs_shipping()) {
         return;
     }
     $cart_contents = edd_get_cart_contents();
     if (!is_array($cart_contents)) {
         return;
     }
     $amount = 0.0;
     foreach ($cart_contents as $key => $item) {
         $price_id = isset($item['options']['price_id']) ? (int) $item['options']['price_id'] : null;
         if (!$this->item_has_shipping($item['id'], $price_id)) {
             continue;
         }
         if (is_user_logged_in() && empty($_POST['country'])) {
             $address = get_user_meta(get_current_user_id(), '_edd_user_address', true);
             if (isset($address['country']) && $address['country'] != $this->get_base_region($item['id'])) {
                 $this->is_domestic = false;
             } else {
                 $this->is_domestic = true;
             }
         } else {
             $country = !empty($_POST['country']) ? $_POST['country'] : $this->get_base_region();
             if ($country != $this->get_base_region($item['id'])) {
                 $this->is_domestic = false;
             } else {
                 $this->is_domestic = true;
             }
         }
         if ($this->is_domestic) {
             $amount = (double) get_post_meta($item['id'], '_edd_shipping_domestic', true);
         } else {
             $amount = (double) get_post_meta($item['id'], '_edd_shipping_international', true);
         }
         if ($amount > 0) {
             EDD()->fees->add_fee(array('amount' => $amount, 'label' => sprintf(__('%s Shipping', 'edd-simple-shipping'), get_the_title($item['id'])), 'id' => 'simple_shipping_' . $key, 'download_id' => $item['id']));
         }
     }
 }
Beispiel #24
0
			<th class="edd_cart_item_price"><?php 
esc_html_e('Item Price', 'helium');
?>
</th>
			<th class="edd_cart_actions"><?php 
esc_html_e('Actions', 'helium');
?>
</th>
			<?php 
do_action('edd_checkout_table_header_last');
?>
		</tr>
	</thead>
	<tbody>
		<?php 
$cart_items = edd_get_cart_contents();
?>
		<?php 
do_action('edd_cart_items_before');
?>
		<?php 
if ($cart_items) {
    ?>
			<?php 
    foreach ($cart_items as $key => $item) {
        ?>
				<tr class="edd_cart_item" id="edd_cart_item_<?php 
        echo esc_attr($key) . '_' . esc_attr($item['id']);
        ?>
" data-download-id="<?php 
        echo esc_attr($item['id']);
/**
 * Ensure cart quantities are OK
 *
 * @since       1.0.0
 * @return      void
 */
function edd_pl_checkout_errors($valid_data, $posted)
{
    global $edd_prices_sold_out;
    $cart = edd_get_cart_contents();
    $scope = edd_get_option('edd_purchase_limit_scope') ? edd_get_option('edd_purchase_limit_scope') : 'site-wide';
    $errors = array();
    foreach ($cart as $item) {
        if (edd_has_variable_prices($item['id'])) {
            if (edd_pl_is_item_sold_out($item['id'], $item['options']['price_id'], false, false)) {
                $errors[] = array('id' => $item['id'], 'price' => $item['options']['price_id'], 'type' => 'soldout', 'avail' => null);
            }
        } else {
            $max_purchases = edd_pl_get_file_purchase_limit($item['id']);
            if ($scope == 'site-wide') {
                $purchases = edd_get_download_sales_stats($item['id']);
                if ($max_purchases && $purchases >= $max_purchases || !empty($edd_prices_sold_out)) {
                    $errors[] = array('id' => $item['id'], 'price' => null, 'type' => 'soldout', 'avail' => null);
                }
            } else {
                if (is_user_logged_in()) {
                    $purchases = edd_pl_get_user_purchase_count(get_current_user_id(), $item['id']);
                    if ($max_purchases && $purchases >= $max_purchases || !empty($edd_prices_sold_out)) {
                        $errors[] = array('id' => $item['id'], 'price' => null, 'type' => 'soldout', 'avail' => null);
                    }
                }
            }
        }
        if (edd_item_in_cart($item['id'])) {
            if (edd_has_variable_prices($item['id'])) {
                $max_purchases = edd_pl_get_file_purchase_limit($item['id'], null, $item['options']['price_id']);
                $purchases = edd_pl_get_file_purchases($item['id'], $item['options']['price_id']);
            }
            if ($max_purchases > 0) {
                $cart_qty = edd_get_cart_item_quantity($item['id']);
                $total = $purchases + $cart_qty;
                if ($total > $max_purchases) {
                    $errors[] = array('id' => $item['id'], 'price' => edd_has_variable_prices($item['id']) ? $item['options']['price_id'] : null, 'type' => 'toomany', 'avail' => $max_purchases - $purchases);
                }
            }
        }
    }
    if (count($errors) > 0) {
        foreach ($errors as $error) {
            $product = get_post($error['id']);
            if ($error['type'] == 'soldout') {
                edd_set_error('purchase_limit_reached', sprintf(__('The %s "%s" is sold out!', 'edd-purchase-limit'), strtolower(edd_get_label_singular()), $product->post_title));
            } elseif ($error['type'] == 'toomany') {
                edd_set_error('purchase_limit_exceeded', sprintf(_n('There is only %s available for the %s "%s"!', 'There are only %s available for the %s "%s"!', $error['avail'], 'edd-purchase-limit'), $error['avail'], strtolower(edd_get_label_singular()), $product->post_title));
            }
        }
    }
}
Beispiel #26
0
 /**
  * Ensure out of stock tickets cannot be purchased even if they manage to get added to the cart
  */
 public function checkout_errors()
 {
     foreach ((array) edd_get_cart_contents() as $item) {
         $remaining = $this->stock_control->available_units($item['id']);
         // We have to append the item IDs otherwise if we have multiple errors of the same type one will overwrite
         // the other
         if (!$remaining) {
             edd_set_error('no_stock_' . $item['id'], sprintf(__('%s ticket is sold out', 'event-tickets-plus'), get_the_title($item['id'])));
         } elseif (self::UNLIMITED !== $remaining && $item['quantity'] > $remaining) {
             edd_set_error('insufficient_stock_' . $item['id'], sprintf(__('Sorry! Only %d tickets remaining for %s', 'event-tickets-plus'), $remaining, get_the_title($item['id'])));
         }
     }
 }
 /**
  * Retrieve all active fees
  *
  * @access public
  * @since 1.5
  * @param string $type Fee type, "fee" or "item"
  * @param int $download_id The download ID whose fees to retrieve
  * @param int $price_id The variable price ID whose fees to retrieve
  * @uses EDD_Session::get()
  * @return array|bool List of fees when available, false when there are no fees
  */
 public function get_fees($type = 'fee', $download_id = 0, $price_id = NULL)
 {
     $fees = EDD()->session->get('edd_cart_fees');
     if (!edd_get_cart_contents()) {
         // We can only get item type fees when the cart is empty
         $type = 'item';
     }
     if (!empty($fees) && !empty($type) && 'all' !== $type) {
         foreach ($fees as $key => $fee) {
             if (!empty($fee['type']) && $type != $fee['type']) {
                 unset($fees[$key]);
             }
         }
     }
     if (!empty($fees) && !empty($download_id)) {
         // Remove fees that don't belong to the specified Download
         foreach ($fees as $key => $fee) {
             if ((int) $download_id !== (int) $fee['download_id']) {
                 unset($fees[$key]);
             }
         }
     }
     // Now that we've removed any fees that are for other Downloads, lets also remove any fees that don't match this price id
     if (!empty($fees) && !empty($download_id) && !is_null($price_id)) {
         // Remove fees that don't belong to the specified Download AND Price ID
         foreach ($fees as $key => $fee) {
             if (is_null($fee['price_id'])) {
                 continue;
             }
             if ((int) $price_id !== (int) $fee['price_id']) {
                 unset($fees[$key]);
             }
         }
     }
     if (!empty($fees)) {
         // Remove fees that belong to a specific download but are not in the cart
         foreach ($fees as $key => $fee) {
             if (empty($fee['download_id'])) {
                 continue;
             }
             if (!edd_item_in_cart($fee['download_id'])) {
                 unset($fees[$key]);
             }
         }
     }
     // Allow 3rd parties to process the fees before returning them
     return apply_filters('edd_fees_get_fees', !empty($fees) ? $fees : array(), $this);
 }
 /**
  * Retrieve all active fees
  *
  * @access public
  * @since 1.5
  * @param string $type Fee type, "fee" or "item"
  * @param int $download_id The download ID whose fees to retrieve
  * @uses EDD_Session::get()
  * @return mixed array|bool
  */
 public function get_fees($type = 'fee', $download_id = 0)
 {
     $fees = EDD()->session->get('edd_cart_fees');
     if (!edd_get_cart_contents()) {
         // We can only get item type fees when the cart is empty
         $type = 'item';
     }
     if (!empty($fees) && !empty($type) && 'all' !== $type) {
         foreach ($fees as $key => $fee) {
             if (!empty($fee['type']) && $type != $fee['type']) {
                 unset($fees[$key]);
             }
         }
     }
     if (!empty($fees) && !empty($download_id)) {
         // Remove fees that don't belong to the specified Download
         foreach ($fees as $key => $fee) {
             if ((int) $download_id !== (int) $fee['download_id']) {
                 unset($fees[$key]);
             }
         }
     }
     if (!empty($fees)) {
         // Remove fees that belong to a specific download but are not in the cart
         foreach ($fees as $key => $fee) {
             if (empty($fee['download_id'])) {
                 continue;
             }
             if (!edd_item_in_cart($fee['download_id'])) {
                 unset($fees[$key]);
             }
         }
     }
     return !empty($fees) ? $fees : array();
 }
/**
 * Get the discounted amount on a price
 *
 * @since 1.9
 * @param array $item Cart item array
 * @return float The discounted amount
 */
function edd_get_cart_item_discount_amount($item = array())
{
    global $edd_is_last_cart_item, $edd_flat_discount_total;
    // If we're not meeting the requirements of the $item array, return or set them
    if (empty($item) || empty($item['id'])) {
        return 0;
    }
    // Quantity is a requirement of the cart options array to determine the discounted price
    if (empty($item['quantity'])) {
        return 0;
    }
    if (!isset($item['options'])) {
        $item['options'] = array();
    }
    $amount = 0;
    $price = edd_get_cart_item_price($item['id'], $item['options']);
    $discounted_price = $price;
    // Retrieve all discounts applied to the cart
    $discounts = edd_get_cart_discounts();
    if ($discounts) {
        foreach ($discounts as $discount) {
            $code_id = edd_get_discount_id_by_code($discount);
            // Check discount exists
            if (!$code_id) {
                continue;
            }
            $reqs = edd_get_discount_product_reqs($code_id);
            $excluded_products = edd_get_discount_excluded_products($code_id);
            // Make sure requirements are set and that this discount shouldn't apply to the whole cart
            if (!empty($reqs) && edd_is_discount_not_global($code_id)) {
                // This is a product(s) specific discount
                foreach ($reqs as $download_id) {
                    if ($download_id == $item['id'] && !in_array($item['id'], $excluded_products)) {
                        $discounted_price -= $price - edd_get_discounted_amount($discount, $price);
                    }
                }
            } else {
                // This is a global cart discount
                if (!in_array($item['id'], $excluded_products)) {
                    if ('flat' === edd_get_discount_type($code_id)) {
                        /* *
                         * In order to correctly record individual item amounts, global flat rate discounts
                         * are distributed across all cart items. The discount amount is divided by the number
                         * of items in the cart and then a portion is evenly applied to each cart item
                         */
                        $items_subtotal = 0.0;
                        $cart_items = edd_get_cart_contents();
                        foreach ($cart_items as $cart_item) {
                            if (!in_array($cart_item['id'], $excluded_products)) {
                                $item_price = edd_get_cart_item_price($cart_item['id'], $cart_item['options']);
                                $items_subtotal += $item_price * $cart_item['quantity'];
                            }
                        }
                        $subtotal_percent = $price * $item['quantity'] / $items_subtotal;
                        $code_amount = edd_get_discount_amount($code_id);
                        $discounted_amount = $code_amount * $subtotal_percent;
                        $discounted_price -= $discounted_amount;
                        $edd_flat_discount_total += round($discounted_amount, edd_currency_decimal_filter());
                        if ($edd_is_last_cart_item && $edd_flat_discount_total < $code_amount) {
                            $adjustment = $code_amount - $edd_flat_discount_total;
                            $discounted_price -= $adjustment;
                        }
                    } else {
                        $discounted_price -= $price - edd_get_discounted_amount($discount, $price);
                    }
                }
            }
        }
        $amount = $price - apply_filters('edd_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price);
        if ('flat' !== edd_get_discount_type($code_id)) {
            $amount = $amount * $item['quantity'];
        }
    }
    return $amount;
}
/**
 * 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();
}