This works globally ...How can I make this CONDITIONAL
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 ); function jk_woocommerce_quantity_input_args( $args, $product ) {
$args['max_value'] = 10; // Maximum value
return $args;
}
Conditions: Product is either on_sale or Featured AND ordertype is DELIVERED
NB: $onsale=WC_Product::is_on_sale();
$product->is_on_sale();
$ordertype is a session variable already set with WC()->session->set( 'ordertype', 'Delivery' )
can be used to check on_sale items
Background
==========
I'm using Avada theme + Woocommerce Thumbnail Input Quantities Plugin - the above code sort of works works ok. (Ideally, it should check as each item is added to cart but..)
I need to set MAX Quantity so tried WooCommerce Advanced Product Quantities but that didn't seem to work. WooCommerce Advanced Product Quantities means more work so less likely that the users will use it!
So I tried above in my Functions.php & it works... but ... Globally on all items in the cart!
above is based on https://docs.woothemes.com/document/adjust-the-quantity-input-value/
This work globally... Not at input (ideally at Input would be nice) but does work at checkout and I can live with that ...
I want to add a condition so it only applies to SALE & FEATURED items
ie. if Product is "on_sale" apply the filter - something link
I think I need to do something like this:
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
If (($onsale or $featured) and $ordertype="Delivery") {
function jk_woocommerce_quantity_input_args( $args, $product ) {
$args['max_value'] = 10; // Maximum value
$args['min_value'] = 1; // Minimum value
return $args;
}
return
}
NB: Tried the above with SALE items but I get a WHITE page error and wholes site is not accessible!
unfortunately my PHP / Woocommerce is not good enough
Rempty answers:
Must be:
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
function jk_woocommerce_quantity_input_args( $args, $product ) {
$onsale=$product->is_on_sale();
if (($onsale or $featured)) {
$args['max_value'] = 10; // Maximum value
$args['min_value'] = 1; // Minimum value
}
return $args;
}
bas mistry comments:
Great Thanks - it works!!
This is my final code.
//Check Qty if On-Sale (or Featured) and Delivery
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 );
function jk_woocommerce_quantity_input_args( $args, $product ) {
$onsale=$product->is_on_sale();
//$featured=$product->is_featured(); // Limit Not applied to Featured items
//$chosen_shipping=WC()->session->get( 'chosen_shipping_methods' ); //Chosen_shipping set to "free_shipping"
if ((($onsale or $featured)) && $chosen_shipping='free_shipping') {
$args['max_value'] = 10; // Maximum value
$args['min_value'] = 1; // Minimum value
}
return $args;
}
Rempty comments:
Dont forge to vote and Mark the question as completed. Thank u.
bas mistry comments:
I have
This is now Complete