Created
December 14, 2020 05:32
-
-
Save kartikparmar/ee5d6c404b9c87bdea2c4ec5a0e0631e to your computer and use it in GitHub Desktop.
Setting minimum quantity when adding the product to cart from shop page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function loop_add_to_cart_args_callback( $args, $product ) { | |
$product_id = $product->get_id(); | |
$product_min = wc_get_product_min_limit( $product_id ); | |
if ( $product_min ) { | |
$args['quantity'] = $product_min; | |
} | |
return $args; | |
} | |
add_filter( 'woocommerce_loop_add_to_cart_args', 'loop_add_to_cart_args_callback', 100, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment