Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'edd_post_add_to_cart', 'gvtheme_edd_post_add_to_cart', 10, 2 );
- /**
- * Prevent adding more than one of a certain download.
- *
- * If a download is already added, this will overwrite the previous configuration with the new one
- *
- * @since 1.0.0
- * @param int $download_id The ID of a specific download
- * @param array $options The options for this downloads
- * @return void
- */
- function gvtheme_edd_post_add_to_cart( $download_id, $options ) {
- $cart = edd_get_cart_contents();
- foreach ( $cart as $key => $item ) {
- if( intval( $download_id ) === intval( $item['id'] ) ) {
- unset( $cart[ $key ] );
- }
- }
- $cart[] = array(
- 'id' => $download_id,
- 'options' => $options,
- 'quantity' => 1
- );
- EDD()->session->set( 'edd_cart', $cart );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement