At WooCommerce, I would like to provide a 10% discount especially for those products that are not for sale. If the number of items in the basket is 5 or more items and not for sale, then I give a 10% discount.
I use the following code to get a discount based on the limit on the number of cart items here:
add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees');
function add_custom_fees( WC_Cart $cart ){
if( $cart->cart_contents_count < 5 ){
return;
}
$discount = $cart->subtotal * 0.1;
$cart->add_fee( '10% discount', -$discount);
}
But I do not know how to apply the discount only to items that are not for sale. How can i achieve this?
Thank.
Osman source
share