• Resolved vincenzo1993dg

    (@vincenzo1993dg)


    I found online a snippet that allows you to set in the cart a minimum purchase to multiple quantities of “6”.
    Here it is:

    // start code

    add_action( ‘woocommerce_check_cart_items’, ‘woocommerce_check_cart_quantities’ );
    function woocommerce_check_cart_quantities() {
    $multiples = 6;
    $total_products = 0;
    foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
    $total_products += $values[‘quantity’];
    }
    if ( ( $total_products % $multiples ) > 0 )
    wc_add_notice( sprintf( __(‘You need to buy in quantities of %s products’, ‘woocommerce’), $multiples ), ‘error’ );
    }

    //end code

    I want this rule to be valid only for products belonging to a specific category, with “id = 35”.
    All products in other categories can also be purchased in smaller quantities.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set minimum purchase to multiples of “x” of products in a specific category’ is closed to new replies.