Loading...
Skip to main content

Shipping Labels – Adding Free! back in

BEFORE

Within WooCommerce 3.0+, you will be using “Shipping Zones” instead of the legacy shipping methods. When you were able to use the legacy version, there was text that was added automatically if the price of the shipping method chosen was $0.00, which was “Free!”. This text also shows up within products, for your reference. See the image above, this is using the new “Shipping Zones” and the method being used having a cost of $0.00. You can see that the “Free!” text is no longer added to the shipping label as was before.

AFTER

Let’s add some text now. The filter we will be using – woocommerce_cart_shipping_method_full_label is fairly easy to understand, but here is the place within WooCommerce where you can take a closer look. You can see that there are two params that are being sent to this filter, which we will be using in our custom function in a second. The first is the actual $label (string), and the second is the $method (object) being chosen. However, in our case, we want to show the “Free!” text when any method is chosen that has a cost of “$0.00”, or is free. To do this we need to capture what the method object returns as the cost, and when we look at the object within the WC function, we see this if ( $method->cost > 0 ) { which tells us the needed information. Our function is going to be using the $method->cost where it is absolutely equal to zero, and then show our added text to the label. Here is our add_filter function:

Let me know what you think about this function/filter, and if it is helpful to you, add a comment below 🙂

No Comments yet!

Your Email address will not be published.


Shopping cart0
There are no products in the cart!
Continue shopping