Thank you for your input, Caleb, although I’m not in total agreement with your assessment. For instance, Shipping Zone methods can be named whatever the user wishes, so it is not absolutely necessary to include “Free” in the name.
And I am not “thinking only about [my] particular need and use-case.” I know there are other store owners who wish to manipulate their shipping rates because I came across their questions and helpful suggestions when I was looking to do so myself. Many online stores offer free/discounted shipping for purchases above a certain amount. I just shopped at a store a few days ago that offered a free shipping method (with “FREE” to the right of its name), and faster methods with costs > $0. So I hardly think I’m the only store owner on the planet looking to do something similar.
I am using the WooCommerce USPS Shipping extension (purchased from WooThemes) and I wrote a function that uses the woocommerce_package_rates filter to change the USPS Media Mail rate to $0 when the subtotal is $50 or higher. Yes, most customers should realize that Media Mail with nothing next to it (as opposed to other methods with dollar amounts next to them) means it’s free. But over the years I’ve occasionally received questions from customers who apparently could not read what was right in front of them, or just couldn’t understand something that other customers were able to figure out with no problem. No one wants to lose a sale simply because something wasn’t fully spelled out for a persnickety customer.
Anyway, I went through the WooCommerce code and found the proper filter to use in order to add “FREE” when a rate is $0. I’m sharing it below for anyone with circumstances similar to mine. I chose to go with all-caps FREE, but just remove the strtoupper function if you’d rather display “Free.”
To simply add “FREE” after all $0-cost method names, add the following to your functions.php file:
add_filter('woocommerce_cart_shipping_method_full_label', 'add_free_label', 10, 2);
function add_free_label($label, $method) {
if ($method->cost == 0) {
$label .= ': '.strtoupper(__( 'Free', 'woocommerce' ));
}
return $label;
}
If you need to exclude a specific method (for instance, if it already has “Free” in its name), use this code instead (replace ‘your_shipping_name_id’ with the id of your method)*:
add_filter('woocommerce_cart_shipping_method_full_label', 'add_free_label', 10, 2);
function add_free_label($label, $method) {
if ($method->cost == 0 && $method->id !== 'your_shipping_name_id') {
$label .= ': '.strtoupper(__( 'Free', 'woocommerce' ));
}
return $label;
}
*Methods added to Shipping Zones are ID’d differently than other methods. The format is method_id:instance_id. For example, the first addition of the Free Shipping method to a Shipping Zone will have “free_shipping:1” as its ID. If you have access to your WP MySQL database, you can figure out the method_id and instance_id by looking at the woocommerce_shipping_zone_methods table.