Free Delivery Fee Logic

User
Please note deliveries are Monday to Friday – orders placed Sat / Sun / Bank Holidays will be delivered on the next business day. Deliveries placed before 10am will be delivered the same working day (subject to availability).
Assistant
To make the delivery fee **free when the order total is above €55**, you need to modify the `apply_custom_delivery_fee` function to include a check for the cart total. Here's the updated version of that function:

### ✅ Updated `apply_custom_delivery_fee` function:

add_action('woocommerce_cart_calculate_fees', 'apply_custom_delivery_fee');
function apply_custom_delivery_fee($cart) {
    if (is_admin() && !defined('DOING_AJAX')) return;

    $fees = [
        'TINAHELY' => 5, 'ARKLOW' => 18, 'ANNACURRA' => 8, 'AUGHRIM' => 12,
        'BALLINGLEN' => 6, 'BALLYCONNELL' => 12, 'CARNEW' => 10,
        'COOLKENNO' => 10, 'HACKETSTOWN' => 10, 'GOREY' => 18,
        'KILTEGAN' => 15, 'KNOCKANANNA' => 10, 'RATHDRUM' => 18,
        'SHILLELAGH' => 7, 'TULLOW' => 18
    ];

    $selected = WC()->session->get('custom_delivery_area');
    
    // ✅ Check if cart total is above 55
    if ($cart->subtotal_ex_tax >= 55) {
        return; // Don't apply delivery fee
    }

    if ($selected && isset($fees[$selected])) {
        $cart->add_fee('Delivery to ' . $selected, $fees[$selected]);
    }
}

### 👀 Why use `$cart->subtotal_ex_tax`?

– It **excludes taxes and shipping fees**, checking **only the actual product subtotal**.
– If you'd rather check **including discounts**, use `$cart->get_subtotal()` instead.
– If you want to check the **final total after discounts**, use `$cart->get_total('edit')`.

Let me know if you’d like to apply the free delivery **after discount** instead — I can tweak that logic for you.

User
display free delivery in place of delivery fees
Assistant
To **display "Free Delivery"** instead of the fee label (when the cart total is over €55), you can update the `apply_custom_delivery_fee()` function to **add a fee with zero cost and a custom label**.

### ✅ Updated `apply_custom_delivery_fee` function:

add_action('woocommerce_cart_calculate_fees', 'apply_custom_delivery_fee');
function apply_custom_delivery_fee($cart) {
    if (is_admin() && !defined('DOING_AJAX')) return;

    $fees = [
        'TINAHELY' => 5, 'ARKLOW' => 18, 'ANNACURRA' => 8, 'AUGHRIM' => 12,
        'BALLINGLEN' => 6, 'BALLYCONNELL' => 12, 'CARNEW' => 10,
        'COOLKENNO' => 10, 'HACKETSTOWN' => 10, 'GOREY' => 18,
        'KILTEGAN' => 15, 'KNOCKANANNA' => 10, 'RATHDRUM' => 18,
        'SHILLELAGH' => 7, 'TULLOW' => 18
    ];

    $selected = WC()->session->get('custom_delivery_area');

    if ($selected && isset($fees[$selected])) {
        if ($cart->subtotal_ex_tax >= 55) {
            $cart->add_fee('Free Delivery to ' . $selected, 0);
        } else {
            $cart->add_fee('Delivery to ' . $selected, $fees[$selected]);
        }
    }
}

### 💡 Optional: Style the free delivery fee on the checkout page

You can also use custom CSS or filters if you want to highlight free delivery in green or bold — just let me know if you'd like that too.

Let me know if you want this logic to be **based on order total including tax or discount** instead of `subtotal_ex_tax`.

Leave a Comment

Your email address will not be published. Required fields are marked *