Home Min and Steps quantity in Woocommerce cart and single product page for wholesale role
Reply: 0

Min and Steps quantity in Woocommerce cart and single product page for wholesale role

user1934
1#
user1934 Published in May 28, 2018, 9:47 am

I have this working except for non-wholesale users on the cart page.

Requirements:

  • Min quantity of 36
  • intervals of 36
  • Apply to single-product-page & cart
  • current_user_can('wholesale')
  • has_term( 'mug', 'product_tag')

This should work but, it applies the rules in the cart to all users when I need it to effect only wholesale users.

add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
function jk_woocommerce_quantity_input_args( $args, $product ) {
    if ( is_cart() || is_checkout()  && has_term( 'mug', 'product_tag') && 
    current_user_can('wholesale') ) {
        $args['input_value'] = 36; // Start from this value (default = 1) 
        $args['min_value']   = 36; // Minimum value
        $args['step']        = 36; // Quantity steps
        return $args;
    } else {
        $args['input_value'] = 1; // Start from this value (default = 1) 
        $args['min_value']   = 1; // Minimum value
        $args['step']        = 1; // Quantity steps
        return $args;
    }
}

// Variations
add_filter( 'woocommerce_available_variation', 'jk_woocommerce_available_variation' );
function jk_woocommerce_available_variation( $args ) {
    if (  has_term( 'mug', 'product_tag') && 
    current_user_can('wholesale') ) {
        $args['input_value'] = 36; // Start from this value (default = 1) 
        $args['min_value']   = 36; // Min quantity (default = 1)
        $args['step']        = 36; // Increment/decrement by this value (default = 1)
        return $args;
    } else {
        $args['min_value']   = 1; // Minimum value
        $args['step']        = 1; // Quantity steps
        $args['input_value'] = 1; // Starting value (we only want to affect product pages, not cart)
        return $args;
    } 
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.336365 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO