WooCommerce – Restore the “(Free)” message when shipping method doesn’t charge any cost.

By default this has been removed from WooCommerce 2.6 to avoid obvious situations such as “Free Shipping: (Free)”, but in some cases it’s required display some message and this is possible with the following code.

<?php
/**
* Display (Free) when shipping method does not charge any cost.
*
* @param String $label Shipping method label.
* @param WC_Shipping_Rate $method Shipping method data.
* @return string
*/
function my_wc_custom_free_shipping_label( $label, $method ) {
// Only apply when is free and not using the free shipping method.
if ( '0.00' === $method->cost && 'free_shipping' !== $method->method_id ) {
$label = sprintf( __( '%s: (Free)', 'text-domain' ), $label );
}
return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'my_wc_custom_free_shipping_label', 10, 2 );

view raw
file.php
hosted with ❤ by GitHub

Note that the code above don’t include any message for the “Free Shipping” method.