edd_add_collection_to_cart

Add Collection to Cart.

Description

(array) edd_add_collection_to_cart( (string) $taxonomy, (mixed) $terms ); 

Adds all downloads within a taxonomy term to the cart.

Returns (array)

Array of IDs for each item added to the cart

Parameters (2)

0. $taxonomy (string)
Name of the taxonomy
1. $terms (mixed)
Slug or ID of the term from which to add ites | An array of terms

Usage

  1. if ( !function_exists( 'edd_add_collection_to_cart' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'easy-digital-downloads/includes/cart/functions.php'; 
  3.  
  4. // Name of the taxonomy 
  5. $taxonomy = ''; 
  6.  
  7. // Slug or ID of the term from which to add ites | An array of terms 
  8. $terms = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = edd_add_collection_to_cart($taxonomy, $terms); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/cart/functions.php  
  1. function edd_add_collection_to_cart( $taxonomy, $terms ) { 
  2. if ( ! is_string( $taxonomy ) ) return false; 
  3.  
  4. if( is_numeric( $terms ) ) { 
  5. $terms = get_term( $terms, $taxonomy ); 
  6. $terms = $terms->slug; 
  7.  
  8. $cart_item_ids = array(); 
  9.  
  10. $args = array( 
  11. 'post_type' => 'download',  
  12. 'posts_per_page' => -1,  
  13. $taxonomy => $terms 
  14. ); 
  15.  
  16. $items = get_posts( $args ); 
  17. if ( $items ) { 
  18. foreach ( $items as $item ) { 
  19. edd_add_to_cart( $item->ID ); 
  20. $cart_item_ids[] = $item->ID; 
  21. return $cart_item_ids;