Hello friends, In this article we w’ll learn “How to set Maximum weight for every order in WooCommerce“. Let’s start if we want to set a limit of 30kg for each order. In WooCommerce, there are several ways to set the parameters for WooCommerce purchase limit.
Here we will use the “woocommerce_check_cart_items” action which is provided by WooCommerce to run the functions and execute the code.
Setting a Maximum Weight for WooCommerce Purchase Limit
Many online stores don’t allow their customers to checkout cart if his purchase product weight exceed a pre set limit.
You need to place the following code in the function.php, located in theme folder.
2 3 4 5 6 7 8 9 10 11 12 13 14 |
add_action('woocommerce_check_cart_items','check_cart_weight'); function check_cart_weight(){ global $woocommerce; $weight = $woocommerce->cart->cart_contents_weight; if( $weight > 30 ){ wc_add_notice( sprintf( __( 'You have %sKg weight and we allow only 30Kg of weight per order.', 'woocommerce' ), $weight ), 'error' ); } } |
Pradeep Maurya is the Professional Web Developer & Designer and the Founder of “Tutorials website”. He lives in Delhi and loves to be a self-dependent person. As an owner, he is trying his best to improve this platform day by day. His passion, dedication and quick decision making ability to stand apart from others. He’s an avid blogger and writes on the publications like Dzone, e27.co