• Resolved Gal Baras

    (@galbaras)


    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]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Pluguin Support Sarmin

    (@sarmina5)

    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.

    Thread Starter Gal Baras

    (@galbaras)

    That’s not worquing for me. I’ve set both min_value and min_qty to 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;
    }
    Thread Starter Gal Baras

    (@galbaras)

    Any thoughts?

    Pluguin Support Sarmin

    (@sarmina5)

    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 set min_value and min_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 rule

    The 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 );

    Thread Starter Gal Baras

    (@galbaras)

    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_validation and woocommerce_after_calculate_totals filters, 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?

    Pluguin Support Sarmin

    (@sarmina5)

    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.

    Thread Starter Gal Baras

    (@galbaras)

    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?

    Pluguin Support Sarmin

    (@sarmina5)

    Please create a ticquet at: http://codeastrology.com/my-support/

Viewing 8 replies - 1 through 8 (of 8 total)

You must be loggued in to reply to this topic.