Here, By this you can Make only one item in cart for checkout in your WordPress – WooCommerce. If you add an another item to cart, then previous one will be removed from cart.
Filter / actions I used:-
add_filter( 'woocommerce_add_to_cart_validation', 'woo_custom_add_to_cart_before' );
Callback:-
// before addto cart, only allow 1 item in a cart
function woo_custom_add_to_cart_before( $cart_item_data ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
// Do nothing with the data and return
return true;
}
Cheersss..
Comments...
Kidu kidu