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!