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 Functions
  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  * Get the contents of the cart
 17  *
 18  * @since 1.0
 19  * @return mixed array if cart isn't empty | false otherwise
 20  */
 21 function edd_get_cart_contents() {
 22     $cart = EDD()->session->get( 'edd_cart' );
 23     return ! empty( $cart ) ? apply_filters( 'edd_cart_contents', $cart ) : false;
 24 }
 25 
 26 /**
 27  * Get Cart Quantity
 28  *
 29  * @since 1.0
 30  * @return int $quantity Quantity of one item in the cart
 31  */
 32 function edd_get_cart_quantity() {
 33     $cart = edd_get_cart_contents();
 34     if ( $cart )
 35         $quantity = count( $cart );
 36     else
 37         $quantity = 0;
 38     return $quantity;
 39 }
 40 
 41 /**
 42  * Add To Cart
 43  *
 44  * Adds a download ID to the shopping cart.
 45  *
 46  * @since 1.0
 47  *
 48  * @param int $download_id Download IDs to be added to the cart
 49  * @param array $options Array of options, such as variable price
 50  *
 51  * @return string Cart key of the new item
 52  */
 53 function edd_add_to_cart( $download_id, $options = array() ) {
 54     $cart = edd_get_cart_contents();
 55     if ( ! edd_item_in_cart( $download_id, $options ) ) {
 56         if( 'download' != get_post_type( $download_id ) )
 57             return; // Not a download product
 58 
 59         do_action( 'edd_pre_add_to_cart', $download_id, $options );
 60 
 61         if ( edd_has_variable_prices( $download_id )  && ! isset( $options['price_id'] ) ) {
 62             // Forces to the first price ID if none is specified and download has variable prices
 63             $options['price_id'] = 0;
 64         }
 65 
 66         $to_add = array();
 67 
 68         if ( isset( $options['price_id'] ) && is_array( $options['price_id'] ) ) {
 69             // Process multiple price options at once
 70             foreach ( $options['price_id'] as $price ) {
 71                 $price_options = array( 'price_id' => $price );
 72                 $to_add[] = apply_filters( 'edd_add_to_cart_item', array( 'id' => $download_id, 'options' => $price_options ) );
 73             }
 74         } else {
 75             // Add a single item
 76             $to_add[] = apply_filters( 'edd_add_to_cart_item', array( 'id' => $download_id, 'options' => $options ) );
 77         }
 78 
 79         if ( is_array( $cart ) ) {
 80             $cart = array_merge( $cart, $to_add );
 81         } else {
 82             $cart = $to_add;
 83         }
 84 
 85         EDD()->session->set( 'edd_cart', $cart );
 86 
 87         do_action( 'edd_post_add_to_cart', $download_id, $options );
 88 
 89         // Clear all the checkout errors, if any
 90         edd_clear_errors();
 91 
 92         return count( $cart ) - 1;
 93     }
 94 }
 95 
 96 /**
 97  * Removes a Download from the Cart
 98  *
 99  * @since 1.0
100  * @param int $cart_key the cart key to remove
101  * @return array Updated cart items
102  */
103 function edd_remove_from_cart( $cart_key ) {
104     $cart = edd_get_cart_contents();
105 
106     do_action( 'edd_pre_remove_from_cart', $cart_key );
107 
108     if ( ! is_array( $cart ) ) {
109         return true; // Empty cart
110     } else {
111         unset( $cart[ $cart_key ] );
112     }
113 
114     EDD()->session->set( 'edd_cart', $cart );
115 
116     do_action( 'edd_post_remove_from_cart', $cart_key );
117 
118     // Clear all the checkout errors, if any
119     edd_clear_errors();
120 
121     return $cart; // The updated cart items
122 }
123 
124 /**
125  * Checks the see if an item is already in the cart and returns a boolean
126  *
127  * @since 1.0
128  * @param int $download_id ID of the download to remove
129  * @return bool Item in the cart or not?
130  */
131 function edd_item_in_cart( $download_id = 0, $options = array() ) {
132     $cart_items = edd_get_cart_contents();
133 
134     $ret = false;
135 
136     if ( is_array( $cart_items ) ) {
137         foreach ( $cart_items as $item ) {
138             if ( $item['id'] == $download_id ) {
139                 if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
140                     if ( $options['price_id'] == $item['options']['price_id'] ) {
141                         $ret = true;
142                         break;
143                     }
144                 } else {
145                     $ret = true;
146                     break;
147                 }
148             }
149         }
150     }
151 
152     return (bool) apply_filters( 'edd_item_in_cart', $ret, $download_id, $options );
153 }
154 
155 /**
156  * Get the Item Position in Cart
157  *
158  * @since 1.0.7.2
159  * @param int $download_id ID of the download to get position of
160  * @return mixed false if empty cart | int $position position of the item in the cart
161  */
162 function edd_get_item_position_in_cart( $download_id ) {
163     $cart_items = edd_get_cart_contents();
164     if ( ! is_array( $cart_items ) ) {
165         return false; // Empty cart
166     } else {
167         foreach ( $cart_items as $position => $item ) {
168             if ( $item['id'] == $download_id ) {
169                 return $position;
170             }
171         }
172     }
173 }
174 
175 /**
176  * Get Cart Item Quantity
177  *
178  * @since 1.0
179  * @param int $item Download (cart item) ID number
180  * @return int $quantity Cart item quantity
181  */
182 function edd_get_cart_item_quantity( $item ) {
183     $cart = edd_get_cart_contents();
184     $item_counts = array_count_values( $cart );
185     $quantity = $item_counts[ $item ];
186     return $quantity;
187 }
188 
189 /**
190  * Get Cart Item Price
191  *
192  * @since 1.0
193  * @param int $item Download (cart item) ID number
194  * @param array $options Optional parameters, used for defining variable prices
195  * @return string Fully formatted price
196  */
197 function edd_cart_item_price( $item_id = 0, $options = array() ) {
198     global $edd_options;
199 
200     $price = edd_get_cart_item_price( $item_id, $options );
201     $label = '';
202 
203     if ( edd_is_cart_taxed() ) {
204 
205         if ( ! edd_prices_show_tax_on_checkout() && edd_prices_include_tax() ) {
206             $label .= ' ' . __( '(ex. tax)', 'edd' );
207         }
208 
209         if ( edd_prices_show_tax_on_checkout() && ! edd_prices_include_tax() ) {
210             $label .= ' ' . __( '(incl. tax)', 'edd' );
211         }
212 
213     }
214 
215     $price = edd_currency_filter( edd_format_amount( $price ) );
216 
217     return esc_html( $price . $label );
218 }
219 
220 /**
221  * Get Cart Item Price
222  *
223  * Gets the price of the cart item.
224  *
225  * @since 1.0
226  * @param int $item Download ID number
227  * @param array $options Optional parameters, used for defining variable prices
228  * @return string Price for this item
229  */
230 function edd_get_cart_item_price( $item_id, $options = array(), $tax = true ) {
231     global $edd_options;
232 
233     $price = edd_get_download_price( $item_id );
234 
235     // If variable prices are enabled, retrieve the options
236     $variable_pricing = get_post_meta( $item_id, '_variable_pricing', true) ;
237 
238     if ( $variable_pricing && ! empty( $options ) ) {
239         // If variable prices are enabled, retrieve the options
240         $prices = get_post_meta( $item_id, 'edd_variable_prices', true );
241         if ( $prices ) {
242             $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : $price;
243         }
244     }
245 
246     // Determine if we need to add tax toe the price
247     if ( $tax &&
248         (
249             ( edd_prices_include_tax() && ! edd_is_cart_taxed() && edd_use_taxes() ) ||
250             ( edd_is_cart_taxed() && edd_prices_show_tax_on_checkout() || ( ! edd_prices_show_tax_on_checkout() && edd_prices_include_tax() ) )
251         )
252     ) {
253         $price = edd_calculate_tax( $price );
254     }
255 
256     return apply_filters( 'edd_cart_item_price', $price, $item_id, $options );
257 }
258 
259 /**
260  * Get Price Name
261  *
262  * Gets the name of the specified price option,
263  * for variable pricing only.
264  *
265  * @since 1.0
266  * @param int $item Download ID number
267  * @param array $options Optional parameters, used for defining variable prices
268  * @return string Name of the price option
269  */
270 function edd_get_price_name( $item_id, $options = array() ) {
271     $return = false;
272     $variable_pricing = get_post_meta($item_id, '_variable_pricing', true);
273     if( $variable_pricing && !empty( $options ) ) {
274         // If variable prices are enabled, retrieve the options
275         $prices = get_post_meta( $item_id, 'edd_variable_prices', true );
276         $name = false;
277         if( $prices ) {
278             if( isset( $prices[ $options['price_id'] ] ) )
279                 $name = $prices[ $options['price_id'] ]['name'];
280         }
281         $return = $name;
282     }
283     return apply_filters( 'edd_get_price_name', $return, $item_id, $options );
284 }
285 
286 /**
287  * Cart Subtotal
288  *
289  * Shows the subtotal for the shopping cart (no taxes)
290  *
291  * @since 1.4
292  * @global $edd_options Array of all the EDD Options
293  * @return float Total amount before taxes fully formatted
294  */
295 function edd_cart_subtotal() {
296     global $edd_options;
297 
298     $tax = ( ( ! edd_prices_show_tax_on_checkout() && edd_prices_include_tax() ) || ( ! edd_prices_include_tax() && edd_prices_show_tax_on_checkout() ) );
299     $price = esc_html( edd_currency_filter( edd_format_amount( edd_get_cart_subtotal() ) ) );
300 
301     if ( edd_is_cart_taxed() ) {
302         if ( ! edd_prices_show_tax_on_checkout() && edd_prices_include_tax() ) {
303             $price .= '<br/><span style="font-weight:normal;text-transform:none;">' . __( '(ex. tax)', 'edd' ) . '</span>';
304         }
305 
306         if ( edd_prices_show_tax_on_checkout() && $edd_options['prices_include_tax'] == 'no' ) {
307             $price .= '<br/><span style="font-weight:normal;text-transform:none;">' . __( '(incl. tax)', 'edd' ) . '</span>';
308         }
309     }
310 
311     return $price;
312 }
313 
314 /**
315  * Get Cart Subtotal
316  *
317  * Gets the total price amount in the cart before taxes and before any discounts
318  * uses edd_get_cart_contents().
319  *
320  * @since 1.3.3
321  * @global $edd_options Array of all the EDD Options
322  * @param bool $tax Whether tax is enabled or not (default: true)
323  * @return float Total amount before taxes
324  */
325 function edd_get_cart_subtotal( $tax = true ) {
326     global $edd_options;
327 
328     $cart_items = edd_get_cart_contents();
329     $amount = 0;
330 
331     if ( $cart_items ) {
332         foreach ( $cart_items as $item ) {
333             $amount += edd_get_cart_item_price( $item['id'], $item['options'], $tax );
334 
335         }
336     }
337 
338     return apply_filters( 'edd_get_cart_subtotal', $amount );
339 }
340 
341 /**
342  * Check if cart has fees applied
343  *
344  * Just a simple wrapper function for EDD_Fees::has_fees()
345  *
346  * @since 1.5
347  * @uses EDD()->fees->has_fees()
348  * @return bool Whether the cart has fees applied or not
349  */
350 function edd_cart_has_fees() {
351     return EDD()->fees->has_fees();
352 }
353 
354 /**
355  * Get Cart Fees
356  *
357  * Just a simple wrapper function for EDD_Fees::get_fees()
358  *
359  * @since 1.5
360  * @uses EDD()->fees->get_fees()
361  * @return array All the cart fees that have been applied
362  */
363 function edd_get_cart_fees() {
364     return EDD()->fees->get_fees();
365 }
366 
367 /**
368  * Get Cart Fee Total
369  *
370  * Just a simple wrapper function for EDD_Fees::total()
371  *
372  * @since 1.5
373  * @uses EDD()->fees->total()
374  * @return float Total Cart Fees
375  */
376 function edd_get_cart_fee_total() {
377     return EDD()->fees->total();
378 }
379 
380 /**
381  * Get Cart Amount
382  *
383  * @since 1.0
384  * @param bool $add_taxes Whether to apply taxes (if enabled) (default: true)
385  * @param bool $local_override Force the local opt-in param - used for when not reading $_POST (default: false)
386  * @return float Total amount
387 */
388 function edd_get_cart_amount( $add_taxes = true, $local_override = false ) {
389     $amount = edd_get_cart_subtotal( false );
390 
391     if ( ! empty( $_POST['edd-discount'] ) || edd_get_cart_discounts() !== false ) {
392         // Retrieve the discount stored in cookies
393         $discounts = edd_get_cart_discounts();
394 
395         // Check for a posted discount
396         $posted_discount = isset( $_POST['edd-discount'] ) ? trim( $_POST['edd-discount'] ) : '';
397 
398         if ( $posted_discount && ! in_array( $posted_discount, $discounts ) ) {
399             // This discount hasn't been applied, so apply it
400             $amount = edd_get_discounted_amount( $posted_discount, $amount );
401         }
402 
403         if( ! empty( $discounts ) ) {
404             // Apply the discounted amount from discounts already applied
405             $amount -= edd_get_cart_discounted_amount();
406         }
407     }
408 
409     if ( edd_use_taxes() && $add_taxes ) {
410         if ( edd_local_taxes_only() && ( isset( $_POST['edd_tax_opt_in'] ) || $local_override ) ) {
411             // Add the tax amount for a local resident
412             $tax = edd_get_cart_tax();
413             $amount += $tax;
414         } elseif ( ! edd_local_taxes_only() ) {
415             // Add the global tax amount
416             $tax = edd_get_cart_tax();
417             $amount += $tax;
418         }
419     }
420 
421     return apply_filters( 'edd_get_cart_amount', $amount, $add_taxes, $local_override );
422 }
423 
424 /**
425  * Get Total Cart Amount
426  *
427  * Returns amount after taxes and discounts
428  *
429  * @since 1.4.1
430  * @global $edd_options Array of all the EDD Options
431  * @param  array $discounts Array of discounts to apply (needed during AJAX calls)
432  * @return float Cart amount
433  */
434 function edd_get_cart_total( $discounts = false ) {
435     global $edd_options;
436 
437     $subtotal = edd_get_cart_subtotal( edd_prices_include_tax() );
438     $fees     = edd_get_cart_fee_total();
439     $cart_tax = edd_is_cart_taxed() ? edd_get_cart_tax( $discounts ) : 0;
440     $discount = edd_get_cart_discounted_amount( $discounts );
441 
442     $total    = $subtotal + $fees + $cart_tax - $discount;
443 
444     return (float) apply_filters( 'edd_get_cart_total', $total );
445 }
446 
447 /**
448  * Get Total Cart Amount
449  *
450  * Gets the fully formatted total price amount in the cart.
451  * uses edd_get_cart_amount().
452  *
453  * @access public
454  * @global $edd_options Array of all the EDD Options
455  * @since 1.3.3
456  * @return string - the cart amount
457  */
458 function edd_cart_total( $echo = true ) {
459     global $edd_options;
460 
461     $total = apply_filters( 'edd_cart_total', edd_currency_filter( edd_format_amount( edd_get_cart_total() ) ) );
462 
463     if ( edd_is_cart_taxed() ) {
464         if ( edd_prices_show_tax_on_checkout() ) {
465             $total .= '<br/><span>'. sprintf( __('(includes %s tax)', 'edd'), edd_cart_tax() ) . '</span>';
466         }
467     }
468 
469     if ( ! $echo ) {
470         return $total;
471     }
472 
473     echo $total;
474 }
475 
476 /**
477  * Get Purchase Summary
478  *
479  * Retrieves the purchase summary.
480  *
481  * @access      public
482  * @since       1.0
483  * @return      string
484  */
485 function edd_get_purchase_summary( $purchase_data, $email = true ) {
486     $summary = '';
487 
488     if ( $email ) {
489         $summary .= $purchase_data['user_email'] . ' - ';
490     }
491 
492     foreach ( $purchase_data['downloads'] as $download ) {
493         $summary .= get_the_title( $download['id'] ) . ', ';
494     }
495 
496     $summary = substr( $summary, 0, -2 );
497 
498     return $summary;
499 }
500 
501 /**
502  * Gets the total tax amount for the cart contents
503  *
504  * @since 1.2.3
505  * @param array $discounts Array of discounts to take into account (required for AJAX calls)
506  * @return string Total tax amount
507  */
508 function edd_get_cart_tax( $discounts = false ) {
509     $subtotal = edd_get_cart_subtotal( false );
510     $subtotal += edd_get_cart_fee_total();
511     $cart_tax = 0;
512 
513     if ( edd_is_cart_taxed() ) {
514 
515         if ( edd_taxes_after_discounts() ) {
516             $subtotal -= edd_get_cart_discounted_amount( $discounts );
517         }
518 
519         $cart_tax = edd_calculate_tax( $subtotal, false );
520 
521     }
522 
523     return apply_filters( 'edd_get_cart_tax', $cart_tax, $subtotal );
524 }
525 
526 /**
527  * Gets the total tax amount for the cart contents in a fully formatted way
528  *
529  * @since 1.2.3
530  * @param bool $echo Whether to echo the tax amount or not (default: false)
531  * @return string Total tax amount (if $echo is set to true)
532  */
533 function edd_cart_tax( $echo = false ) {
534     $cart_tax = 0;
535 
536     if ( edd_is_cart_taxed() ) {
537         $cart_tax = edd_get_cart_tax();
538         $cart_tax = edd_currency_filter( edd_format_amount( $cart_tax ) );
539     }
540 
541     $tax = apply_filters( 'edd_cart_tax', $cart_tax );
542 
543     if ( ! $echo ) {
544         return $tax;
545     }
546 
547     echo $tax;
548 }
549 
550 /**
551  * Retrieve the Cart Content Details
552  *
553  * @since 1.0
554  * @return array $defailt Cart content details
555  */
556 function edd_get_cart_content_details() {
557     $cart_items = edd_get_cart_contents();
558     if ( empty( $cart_items ) ) return false;
559 
560     $details  = array();
561     $is_taxed = edd_is_cart_taxed();
562 
563     foreach( $cart_items as $key => $item ) {
564 
565         $price = edd_get_cart_item_price( $item['id'], $item['options'] );
566         $non_taxed_price = edd_get_cart_item_price( $item['id'], $item['options'], false );
567 
568         $details[ $key ]  = array(
569             'name'        => get_the_title( $item['id'] ),
570             'id'          => $item['id'],
571             'item_number' => $item,
572             'price'       => $price,
573             'quantity'    => 1,
574             'tax'         => $is_taxed ? edd_calculate_tax( $non_taxed_price, false ) : 0,
575         );
576     }
577 
578     return $details;
579 }
580 
581 /**
582  * Add Collection to Cart
583  *
584  * Adds all downloads within a taxonomy term to the cart.
585  *
586  * @since 1.0.6
587  * @param string $taxonomy Name of the taxonomy
588  * @param mixed $terms Slug or ID of the term from which to add ites | An array of terms
589  * @return array Array of IDs for each item added to the cart
590  */
591 function edd_add_collection_to_cart( $taxonomy, $terms ) {
592     if ( ! is_string( $taxonomy ) ) return false;
593 
594     $field = is_int( $terms ) ? 'id' : 'slug';
595 
596     $cart_item_ids = array();
597 
598     $args = array(
599         'post_type' => 'download',
600         'posts_per_page' => -1,
601         $taxonomy => $terms
602     );
603 
604     $items = get_posts( $args );
605     if ( $items ) {
606         foreach ( $items as $item ) {
607             edd_add_to_cart( $item->ID );
608             $cart_item_ids[] = $item->ID;
609         }
610     }
611     return $cart_item_ids;
612 }
613 
614 /**
615  * Returns the URL to remove an item from the cart
616  *
617  * @since 1.0
618  * @global $post
619  * @param int $cart_key Cart item key
620  * @param object $post Download (post) object
621  * @param bool $ajax AJAX?
622  * @return string $remove_url URL to remove the cart item
623  */
624 function edd_remove_item_url( $cart_key, $post, $ajax = false ) {
625     global $post;
626 
627     if( is_page() ) {
628         $current_page = add_query_arg( 'page_id', $post->ID, home_url('/') );
629     } else if( is_singular() ) {
630         $current_page = add_query_arg( 'p', $post->ID, home_url('/') );
631     } else {
632         $current_page = edd_get_current_page_url();
633     }
634     $remove_url = add_query_arg( array('cart_item' => $cart_key, 'edd_action' => 'remove' ), $current_page );
635 
636     return apply_filters( 'edd_remove_item_url', $remove_url );
637 }
638 
639 /**
640  * Show Added To Cart Messages
641  *
642  * @since 1.0
643  * @param int $download_id Download (Post) ID
644  * @return void
645  */
646 function edd_show_added_to_cart_messages( $download_id ) {
647     if ( isset( $_POST['edd_action'] ) && $_POST['edd_action'] == 'add_to_cart' ) {
648         $alert = '<div class="edd_added_to_cart_alert">'
649         . sprintf( __('You have successfully added %s to your shopping cart.', 'edd'), get_the_title( $download_id ) )
650         . ' <a href="' . edd_get_checkout_uri() . '" class="edd_alert_checkout_link">' . __('Checkout.', 'edd') . '</a>'
651         . '</div>';
652 
653         echo apply_filters( 'edd_show_added_to_cart_messages', $alert );
654     }
655 }
656 add_action('edd_after_download_content', 'edd_show_added_to_cart_messages');
657 
658 /**
659  * Get the URL of the Checkout page
660  *
661  * @since 1.0.8
662  * @global $edd_options Array of all the EDD Options
663  * @param array $args Extra query args to add to the URI
664  * @return mixed Full URL to the checkout page, if present | null if it doesn't exist
665  */
666 function edd_get_checkout_uri( $args = array() ) {
667     global $edd_options;
668 
669     $uri = isset( $edd_options['purchase_page'] ) ? get_permalink( $edd_options['purchase_page'] ) : NULL;
670 
671     if ( ! empty( $args ) ) {
672         // Check for backward compatibility
673         if ( is_string( $args ) )
674             $args = str_replace( '?', '', $args );
675 
676         $args = wp_parse_args( $args );
677 
678         $uri = add_query_arg( $args, $uri );
679     }
680 
681     $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
682 
683     $ajax_url = admin_url( 'admin-ajax.php', $scheme );
684 
685     if ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) {
686         $uri = preg_replace( '/^http/', 'https', $uri );
687     }
688 
689     if ( isset( $edd_options['no_cache_checkout'] ) && edd_is_caching_plugin_active() )
690         $uri = add_query_arg( 'nocache', 'true', $uri );
691 
692     return apply_filters( 'edd_get_checkout_uri', $uri );
693 }
694 
695 /**
696  * Get the URL of the Transaction Failed page
697  *
698  * @since 1.3.4
699  * @global $edd_options Array of all the EDD Options
700  * @param string $extras Extras to append to the URL
701  * @return string Full URL to the Transaction Failed page, if present, home page if it doesn't exist
702  */
703 function edd_get_failed_transaction_uri( $extras = false ) {
704     global $edd_options;
705 
706     $uri = isset( $edd_options['failure_page'] ) ? trailingslashit( get_permalink( $edd_options['failure_page'] ) ) : home_url();
707     if ( $extras )
708         $uri .= $extras;
709 
710     return apply_filters( 'edd_get_failed_transaction_uri', $uri );
711 }
712 
713 /**
714  * Determines if we're currently on the Checkout page
715  *
716  * @since 1.1.2
717  * @return bool True if on the Checkout page, false otherwise
718  */
719 function edd_is_checkout() {
720     global $edd_options;
721     $is_checkout = isset( $edd_options['purchase_page'] ) ? is_page( $edd_options['purchase_page'] ) : false;
722     return apply_filters( 'edd_is_checkout', $is_checkout );
723 }
724 
725 /**
726  * Empties the Cart
727  *
728  * @since 1.0
729  * @uses EDD()->session->set()
730  * @return void
731  */
732 function edd_empty_cart() {
733     // Remove cart contents
734     EDD()->session->set('edd_cart', NULL );
735 
736     // Remove any active discounts
737     edd_unset_all_cart_discounts();
738 }
739 
740 /**
741  * Store Purchase Data in Sessions
742  *
743  * Used for storing info about purchase
744  *
745  * @since 1.1.5
746  * @uses EDD()->session->set()
747  * @return void
748  */
749 function edd_set_purchase_session( $purchase_data ) {
750     EDD()->session->set('edd_purchase', $purchase_data );
751 }
752 
753 /**
754  * Retrieve Purchase Data from Session
755  *
756  * Used for retrieving info about purchase
757  * after completing a purchase
758  *
759  * @since 1.1.5
760  * @uses EDD()->session->get()
761  * @return mixed array | false
762  */
763 function edd_get_purchase_session() {
764     return EDD()->session->get('edd_purchase');
765 }
766 
Easy Digital Downloads API documentation generated by ApiGen 2.8.0