Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rajeshsingh520/95b8bba7504baa30f2436a2495b003f3 to your computer and use it in GitHub Desktop.
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
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