Created
May 28, 2025 09:48
-
-
Save rajeshsingh520/95b8bba7504baa30f2436a2495b003f3 to your computer and use it in GitHub Desktop.
Show shipping cost but do not apply it in the final checkout total
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('woocommerce_package_rates', 'override_shipping_cost_to_zero_but_keep_label', PHP_INT_MAX, 2); | |
function override_shipping_cost_to_zero_but_keep_label($rates, $package) { | |
foreach ($rates as $rate_id => $rate) { | |
// Save original cost in the label for display | |
$original_cost = wc_price($rate->cost); | |
$rates[$rate_id]->label .= " (Normally $original_cost)"; | |
// Override actual cost to 0 | |
$rates[$rate_id]->cost = 0; | |
// If taxes exist, zero them too | |
if (!empty($rates[$rate_id]->taxes)) { | |
foreach ($rates[$rate_id]->taxes as $key => $value) { | |
$rates[$rate_id]->taxes[$key] = 0; | |
} | |
} | |
} | |
return $rates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment