Shipping methods in WooCommerce can only have one title / label. But what if you need the title to change conditionally based on the actual cost of the shipping method? Consider the following flat rate shipping method. If a “Large Item” is in the cart, shipping will cost $10. Otherwise, the flat rate method will actually end up costing $0. So rather than showing “Flat Rate: $0” at checkout, you may want to just say “Free Shipping” to the customer.
The following code snippet will rename the shipping label during checkout if the method is flat rate and the cost is $0:
// Rename the flat rate shipping label when the cost is $0
function wc_ninja_change_flat_rate_label( $label, $method ) {
if ( 'flat_rate' === $method->method_id && $method->cost == 0 ) {
$label = "Free Shipping";
}
return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'wc_ninja_change_flat_rate_label', 10, 2 );
This is particularly useful when your free shipping conditions exceed the simple “minimum order amount” option found within the free shipping method. Flat rate is actually a far more powerful shipping option than you might be aware of. Check out this article for some of the possible things you can do with flat rate shipping.
Here is a guide on where to place this custom code if you aren’t sure where it belongs.
It works!
Thanks for sharing