Home > OS >  Woocommerce - Max quantity per variation limit and message
Woocommerce - Max quantity per variation limit and message

Time:06-25

I am using this code to limit the quantity the customers can buy per product :

add_filter( 'woocommerce_available_variation', 'woo_quantity_max_variation', 9999, 3 );
 

function woo_quantity_max_variation( $args, $product, $variation ) {

 $args['max_qty'] =3;

return $args;

}

I need to add a message in the single product page (maybe over or under the quantity) that says for example "Max quantity is 3 units per customer"

Thanks!

CodePudding user response:

You can use

wc_add_notice(  'Your message',  'error' ); 

view complete document here http://hookr.io/functions/wc_add_notice/

CodePudding user response:

You can add the message before the quantity input using woocommerce_before_add_to_cart_quantity action hook.

add_action( 'woocommerce_before_add_to_cart_quantity', 'max_qty_msg' );
function max_qty_msg() {
    ?>
    <h3><?php _e( 'Max quantity is 3 units per customer', '' ); ?></h3>
    <?php
}
  • Related