Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Functions

  • edd_add_collection_to_cart
  • edd_add_rewrite_endpoints
  • edd_add_to_cart
  • edd_cart_has_fees
  • edd_cart_item_price
  • edd_cart_subtotal
  • edd_cart_tax
  • edd_cart_total
  • edd_checkout_cart
  • edd_empty_cart
  • edd_empty_cart_message
  • edd_empty_checkout_cart
  • edd_get_cart_amount
  • edd_get_cart_content_details
  • edd_get_cart_contents
  • edd_get_cart_fee_total
  • edd_get_cart_fees
  • edd_get_cart_item_price
  • edd_get_cart_item_quantity
  • edd_get_cart_item_template
  • edd_get_cart_quantity
  • edd_get_cart_subtotal
  • edd_get_cart_tax
  • edd_get_cart_total
  • edd_get_checkout_uri
  • edd_get_failed_transaction_uri
  • edd_get_item_position_in_cart
  • edd_get_price_name
  • edd_get_purchase_session
  • edd_get_purchase_summary
  • edd_is_checkout
  • edd_item_in_cart
  • edd_process_add_to_cart
  • edd_process_cart_endpoints
  • edd_process_collection_purchase
  • edd_process_remove_from_cart
  • edd_remove_from_cart
  • edd_remove_item_url
  • edd_set_purchase_session
  • edd_shopping_cart
  • edd_show_added_to_cart_messages
  1 <?php
  2 /**
  3  * Cart Actions
  4  *
  5  * @package     EDD
  6  * @subpackage  Cart
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.0
 10  */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 /**
 16  * Register Endpoints for the Cart
 17  *
 18  * These endpoints are used for adding/removing items from the cart
 19  *
 20  * @since 1.3.4
 21  * @return void
 22  */
 23 function edd_add_rewrite_endpoints( $rewrite_rules ) {
 24     add_rewrite_endpoint( 'edd-add', EP_ALL );
 25     add_rewrite_endpoint( 'edd-remove', EP_ALL );
 26 }
 27 add_action( 'init', 'edd_add_rewrite_endpoints' );
 28 
 29 /**
 30  * Process Cart Endpointss
 31  *
 32  * Listens for add/remove requests sent from the cart
 33  *
 34  * @since 1.3.4
 35  * @global $wp_query Used to access the current query that is being requested
 36  * @return void
 37 */
 38 function edd_process_cart_endpoints() {
 39     global $wp_query;
 40 
 41     // Adds an item to the cart with a /edd-add/# URL
 42     if ( isset( $wp_query->query_vars['edd-add'] ) ) {
 43         $download_id = absint( $wp_query->query_vars['edd-add'] );
 44         $cart        = edd_add_to_cart( $download_id, array() );
 45 
 46         wp_redirect( edd_get_checkout_uri() ); exit;
 47     }
 48 
 49     // Removes an item from the cart with a /edd-remove/# URL
 50     if ( isset( $wp_query->query_vars['edd-remove'] ) ) {
 51         $cart_key = absint( $wp_query->query_vars['edd-remove'] );
 52         $cart     = edd_remove_from_cart( $cart_key );
 53 
 54         wp_redirect( edd_get_checkout_uri() ); exit;
 55     }
 56 }
 57 add_action( 'template_redirect', 'edd_process_cart_endpoints', 100 );
 58 
 59 /**
 60  * Process the Add to Cart request
 61  *
 62  * @since 1.0
 63  * @return void
 64  */
 65 function edd_process_add_to_cart( $data ) {
 66     $download_id = $data['download_id'];
 67     $options     = isset( $data['edd_options'] ) ? $data['edd_options'] : array();
 68     $cart        = edd_add_to_cart( $download_id, $options );
 69 
 70     if ( edd_straight_to_checkout() && ! edd_is_checkout() ) {
 71         wp_redirect( edd_get_checkout_uri(), 303 );
 72         exit;
 73     }
 74 }
 75 add_action( 'edd_add_to_cart', 'edd_process_add_to_cart' );
 76 
 77 /**
 78  * Process the Remove form Cart request
 79  *
 80  * @since 1.0
 81  * @return void
 82  */
 83 function edd_process_remove_from_cart( $data ) {
 84     $cart_key = $_GET['cart_item'];
 85     $cart = edd_remove_from_cart( $cart_key );
 86 }
 87 add_action( 'edd_remove', 'edd_process_remove_from_cart' );
 88 
 89 /**
 90  * Process the Collection Purchase request
 91  *
 92  * @since 1.0
 93  * @return void
 94  */
 95 function edd_process_collection_purchase( $data ) {
 96     $taxonomy = urldecode( $data['taxonomy'] );
 97     $terms = urldecode( $data['terms'] );
 98     $cart_items = edd_add_collection_to_cart( $taxonomy, $terms );
 99     wp_redirect( add_query_arg( 'added', '1', remove_query_arg( array( 'edd_action', 'taxonomy', 'terms' ) ) ) );
100     exit;
101 }
102 add_action( 'edd_purchase_collection', 'edd_process_collection_purchase' );
Easy Digital Downloads API documentation generated by ApiGen 2.8.0