If the visitor adds a product at a quantity less than required minimum of 10 (5 for example) and logs in afterwards to view the cart page, the price and the quantity value will automatically change for the visitor. But the issue is that the order total did not - the total considers 5 to be the quantity input rather than 10. How could I add a conditional statement where IF the quantity inputed by user for any product is less than the required minimum, automatically update the total with the required quantity of 10?
I've tried to have the jQuery run when the "View Cart" icon is clicked and have the total be automatically updated to the correct quantity.
This is the function that sets the input quantity and minimum quantity to be 10:
function woocommerce_quantity_changes( $args, $product ) {
if ( current_user_can ('wholesale_customer') ){
if ( ! is_cart() ) {
$args['input_value'] = 10;
$args['max_value'] = -1;
$args['min_value'] = 10;
$args['step'] = 1;
} else {
$args['max_value'] = -1;
$args['step'] = 1;
$args['min_value'] = 10;
}
}
return $args;
}
This is the function that automatically updates the cart:
function cart_refresh_update_qty() {
if (is_cart()) {
?>
<script type="text/javascript">
jQuery('div.woocommerce').on('change', 'input.qty', function(){
jQuery("[name='update_cart']").trigger("click");
});
</script>
<?php
}
}
If a product costs $5.00 at retail price and a non-wholesale user enters in 5 as the quantity, the output is $25.00 in the total, which is correct. If the user logs in as a wholesale customer, the price changes to $2.00 and the expected result is $20.00 since the required minimum is 10. But the actual result is $10.00 (5 * $2.00). If the user initially entered a quantity greater than 10 before logging in, the total automatically adjusts correctly after logging in.