I am manually modifying the price of the cart total (to £10) when there are 4 items in the cart and none of the items are from the category: christmas.
This essentially gives the user a discount + "Free Shipping". However, the total does not match up and it can be confusing to the user as shipping is still shown as charged.
Is there a way to manually apply a dummy "Free Shipping Applied -£3.00" to the cart based on these conditions? Just to make it clearer for the user?
I understand that the hook I am using currently is to modify the price manually, but not for formatted price display.
add_filter( 'woocommerce_calculated_total', 'calculated_total', 10, 2 );
function calculated_total( $total, $cart ) {
$taster_count = 4;
$item_count = $cart->get_cart_contents_count();
$chistm_count = 0;
foreach ( $cart->get_cart() as $cart_item ) {
if ( ! has_term( 'christmas', 'product_cat', $cart_item['product_id'] ) ) {
$chistm_count += $cart_item['quantity'];
}
}
if( $taster_count == $item_count && $chistm_count == $taster_count )
//HERE TRY TO DISPLAY A DUMMY FREE SHIPPING MESSAGE
$discount = 3.00;
$cart->add_fee( 'Taster Box Offer! Free Shipping', -$discount);
return 10;
return $total;
}
Figured out how to solve this. I manually added a woocommerce_cart_calculate_fee
of $3.00 then to minus this off the total to act as a "negative fee" i.e. A discount.
add_filter( 'woocommerce_cart_calculate_fees', 'add_recurring_postage_fees2', 10, 1 );
function add_recurring_postage_fees2(WC_Cart $cart ) {
$items_count = WC()->cart->get_cart_contents_count();
if ( $items_count == 4 ) {
$discount = 3.00;
$cart->add_fee( 'Taster Box Free Shipping', -$discount);
return;
}
}