Add only one product to cart
Mon Mar 13 2023 16:53:09 GMT+0000 (Coordinated Universal Time)
Saved by
@ezeetech21
<?php
add_filter( 'woocommerce_add_to_cart_redirect', function() {
return wc_get_checkout_url();
});
add_filter( 'wc_add_to_cart_message_html' , function() {
return '';
});
add_filter( 'woocommerce_add_to_cart_validation', function( $passed, $product_id, $quantity ) {
if( ! WC()->cart->is_empty() ) {
WC()->cart->empty_cart();
}
return $passed;
}
, 20, 3 );
remove_action( 'woocommerce_order_details_after_order_table', 'woocommerce_order_again_button' );
content_copyCOPY
For selling just one item, for example when you have to pick from multiple prices in a pricing table. This snippet will remove the other products from the cart, and add the current product and will redirect you to checkout. It will also remove the order again button.
Comments