Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. <?php
  2.  
  3. add_action( 'edd_post_add_to_cart', 'gvtheme_edd_post_add_to_cart', 10, 2 );
  4.  
  5. /**
  6. * Prevent adding more than one of a certain download.
  7. *
  8. * If a download is already added, this will overwrite the previous configuration with the new one
  9. *
  10. * @since 1.0.0
  11. * @param int $download_id The ID of a specific download
  12. * @param array $options The options for this downloads
  13. * @return void
  14. */
  15. function gvtheme_edd_post_add_to_cart( $download_id, $options ) {
  16.  
  17. $cart = edd_get_cart_contents();
  18.  
  19. foreach ( $cart as $key => $item ) {
  20. if( intval( $download_id ) === intval( $item['id'] ) ) {
  21. unset( $cart[ $key ] );
  22. }
  23. }
  24.  
  25. $cart[] = array(
  26. 'id' => $download_id,
  27. 'options' => $options,
  28. 'quantity' => 1
  29. );
  30.  
  31. EDD()->session->set( 'edd_cart', $cart );
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement