Home Forums WoodMart support forum Minimum order quantity.

Minimum order quantity.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #379805

    kedm
    Participant

    Hi,

    I was wondering if you could help with a problem I have. I am using this code to allow two user roles (“default_wholesaler” and “top-reseller”) to only order and add to cart in batches of 12 products (apart from sku 9998). The code works everywhere else, except for the product loops. The product loops show a quantity of 12 but the “data-quantity” is 1 by default. The default value should be 12 for the user roles. Do you have any idea how this could be fixed? Here is the code:

    add_filter( ‘woocommerce_quantity_input_args’, ‘custom_quantity_input_args’, 10, 2 );
    function custom_quantity_input_args( $args, $product ) {
    $user = wp_get_current_user(); // Get current WP_User
    if ( is_admin() ) return $args;
    // only for these two roles
    if ( in_array( ‘default_wholesaler’, $user->roles ) || in_array( ‘top-reseller’, $user->roles ) ) {
    //$product_id = $product->is_type(‘variation’) ? $product->get_parent_id() : $product->get_id();
    if ( $product->get_sku() == 9998 ) {
    $args[‘input_value’] = 6; // Start from this value (default = 1)
    $args[‘min_value’] = 6; // Min value (default = 0)
    $args[‘step’] = 6; // Quantity steps (default = 1)
    }
    else {
    $args[‘input_value’] = 12; // Start from this value (default = 1)
    $args[‘min_value’] = 12; // Min value (default = 0)
    $args[‘step’] = 12; // Quantity steps (default = 1)
    }
    }

    if ( $product->get_sku() == 9998 ) {
    $args[‘input_value’] = 6; // Start from this value (default = 1)
    $args[‘min_value’] = 6; // Min value (default = 0)
    $args[‘step’] = 6; // Quantity steps (default = 1)
    }

    return $args;
    }

    Thank you very much in advance!

    #379860

    Artem Temos
    Keymaster

    Hello,

    Actually, it should work on the shop page too. But we don’t know why it doesn’t and it may require deep troubleshooting to see why it doesn’t work. It is out of our theme support scope since this code is not a part of the theme.

    Kind Regards

Viewing 2 posts - 1 through 2 (of 2 total)