How to clear easy digital download (edd) cart before adding to cart? (allow only one item per cart)

657 Views Asked by At

How to clear easy digital download (edd) cart before adding to cart? allow only one item per cart

2

There are 2 best solutions below

0
On

Altenative for devolopment;

   /**
 * If there is more than 1 item in the basket and the total price is 0, the basket will be emptied.
 */
function pw_edd_one_item_checkout( $download_id, $options ) {
    if( edd_get_cart_quantity() >= 1 && edd_get_cart_total() == 0) {
        edd_empty_cart();
    }
}
add_action( 'edd_pre_add_to_cart', 'pw_edd_one_item_checkout', 10, 2 );

0
On

actually i found the answer before joining stack overflow, but very hard and with many search and try. now i decide to share it again here to make it easy to find answer for others.

just add code bellow to function.php

add_filter( 'edd_pre_add_to_cart_contents', '__return_false' );

source: https://wordpress.stackexchange.com/questions/308362/force-customers-to-add-only-single-item-to-card-per-purchase-edd