In WooCommerce, I would like to give a discount of 10% specifically for those products that are not on sale. If cart item count is 5 or more items and not on sale, then I give a discount of 10%.
I use the following code to get a discount based on cart item count restriction here:
add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees');
/**
* Add custom fee if more than three article
* @param WC_Cart $cart
*/
function add_custom_fees( WC_Cart $cart ){
if( $cart->cart_contents_count < 5 ){
return;
}
// Calculate the amount to reduce
$discount = $cart->subtotal * 0.1;
$cart->add_fee( '10% discount', -$discount);
}
But I don't know how to apply the discount only for items that are not in sale. How can I achieve it?
Thanks.
Here is a custom hooked function that will apply to cart a discount, if there is 5 or more items in cart and no products on sale:
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works perfectly.