0

I am trying to modify the total price of the cart to £10.00, ONLY if there are 4 items in the cart. If there are 3,5,6,7 etc...do not apply the discount rule.

I'm having problems with the below snippet.

  1. Firstly the discount triggers no matter what number of items are in the cart even after explicitly defining the count
  2. I can't figure out how to set the price of the cart to be £10.00, I can only apply a discount based on amount of items.

Can anyone offer some assistance please?

// Hook before calculate fees
add_action('woocommerce_cart_calculate_fees' , 'add_custom_fees');

/**
 * Add custom fee if more than three article
 * @param WC_Cart $cart
 */

$taster_item_count = 4;

function add_custom_fees( WC_Cart $cart ){
    if( $cart->cart_contents_count == $taster_item_count ){
        return;
    }

    // Calculate the amount to reduce
    $discount = $cart->subtotal * 0.1;
    $cart->add_fee( 'TASTER BOX DISCOUNT APPLIED', -$discount);
}
Giuls
  • 570
  • 11
  • 33

0 Answers0