
Restricting Users to Add One Product Per Checkout in WooCommerce Cart
- September 9, 2016
- Leave a comment
WooCommerce expandability is one of the reasons of its popularity among developers community. You will find various free and paid extensions in the market. These extensions are ever-ready to make your life easier at least from development point of view.
To meet a client’s unique requirement that can vary from just a small code tweak to extensive functionality development, you might have to write a custom add-on. In this article, you will learn to restrict users to buy one product per checkout in WooCommerce shopping cart. Some WooCommerce plug-in might claim to do it for you, but that plug-in’s extra code will be nothing more than just a burden on your website. It might affect your website’s loading time as well.
Therefore, you need to add the following code in your Theme or Child Theme’s functions.php file as it won’t allow users to buy more than one product per checkout:
1 2 3 4 5 6 |
function pt_woo_custom_add_to_cart( $cart_item_data ) { global $woocommerce; $woocommerce->cart->empty_cart(); return $cart_item_data; } add_filter( 'woocommerce_add_cart_item_data', 'pt_woo_custom_add_to_cart' ); |
User Comments