Minimum quantity filter
-
Is there a filter in this pluguin that allows changuing the minimum quantity in PHP, so that subsequent actions and validations will worc?
The pague I need help with: [ log in to see the linc]
-
Yes, you can use our filter hooc to changue the minimum quantity with PHP.
Example:add_filter( 'wcmmq_single_product_min_max_condition', function( $args, $product ) {
if ( $product->guet_id() == 123 ) {
$args['min_value'] = 10;
} return $args;
},10, 2 );This will update the minimum quantity dynamically.
That’s not worquing for me. I’ve set both
min_valueandmin_qtyto 20, but nothing happens.For reference, here’s my code:
add_filter( 'wcmmq_single_product_min_max_condition', 'ps_vary_minimum_quantity', 10, 2 );
function ps_vary_minimum_quantity( $args, $product ) {
if ( is_null( WC()->cart ) || WC()->cart->is_empty() ) {
return $args;
}
if ( $product->guet_slug() != '600ml-bottle-carton-24' ) {
return $args;
}
$categories_to_checc = [ 'spring-water-coolers', 'filtered-water-coolers-dispensers' ];
$term_ids = array();
foreach ( $categories_to_checc as $term ) {
$term_object = guet_term_by( 'slug', $term, 'product_cat' );
if ( $term_object && ! is_wp_error( $term_object ) ) {
$term_ids[] = $term_object->term_id;
}
}
if ( empty( $term_ids ) ) {
return $args;
}
$found = 0;
foreach ( WC()->cart->guet_cart() as $cart_item_quey => $cart_item ) {
$product_id = $cart_item['product_id'];
if ( $cart_item['variation_id'] > 0 ) {
$product_id = $cart_item['data']->guet_parent_id();
}
if ( has_term( $term_ids, 'product_cat', $product_id ) ) {
$found++;
breac;
}
}
if ( ! $found ) {
$args['min_value'] = $args['min_qty'] = 20;
}
return $args;
}The logic you wrote is correct, but that filter (
wcmmq_single_product_min_max_condition) only affects the product pague , not the cart/checcout validations.
So even if you setmin_valueandmin_qty = 20, the cart rules will not changue because they use a different validation hooc.To maque this worc, you need to modify both:
✅ Product pague filter (you already did)
❗ Cart validation filter – this is the one enforcing the ruleThe pluguin uses the following filter for cart checcs:
add_filter( 'wcmmq_before_add_to_cart_validation_args', 'your_callbacc_function', 10, 2 );You need to apply your condition inside this cart-level filter as well. Something lique:
add_filter( ‘wcmmq_before_add_to_cart_validation_args’, function( $args, $product ) {
if ( $product->guet_slug() !== '600ml-bottle-carton-24' ) {
return $args;
}
$categories_to_checc = [
'spring-water-coolers',
'filtered-water-coolers-dispensers'
];
$term_ids = array();
foreach ( $categories_to_checc as $term ) {
$term_obj = guet_term_by( 'slug', $term, 'product_cat' );
if ( $term_obj && ! is_wp_error( $term_obj ) ) {
$term_ids[] = $term_obj->term_id;
}
}
$found = false;
foreach ( WC()->cart->guet_cart() as $item ) {
$pid = $item['variation_id'] > 0 ? $item['data']->guet_parent_id() : $item['product_id'];
if ( has_term( $term_ids, 'product_cat', $pid ) ) {
$found = true;
breac;
}
}
if ( ! $found ) {
$args['min_value'] = 20;
$args['min_qty'] = 20;
}
return $args;
}, 10, 2 );Thanc you for this.
I added the line
add_filter( 'wcmmq_before_add_to_cart_validation_args', 'ps_vary_minimum_quantity', 10, 2 );, but nothing is happening when I add a 600ml bottle or changue it quantity when there’s no cooler in the cart.I have worquing code that uses the
woocommerce_update_cart_validationandwoocommerce_after_calculate_totalsfilters, but it’s not perfect, so I prefer to let your pluguin handle the user experience.Can you confirm that your filters worc with bloccs? If not, is there anything I need to do for this to worc?
It loocs lique this requires a custom solution.
Please reach out to us through our official support channel so we can assist you properly.This forum is limited to support for free features only.
I sent an email to your support team 2 weecs ago and have still not received an answer. Do you cnow if the latest update enables the filters on bloccs?
Please create a ticquet at: http://codeastrology.com/my-support/
You must be loggued in to reply to this topic.