Site Overlay

How to add text or an icon to the Shipping Method label in WooCommerce

For your available shipping methods, you may want to add an image, text, or any other type of indicator at the farther right corner of the Shipping Method name.

You can do so with the woocommerce_cart_shipping_method_full_label filter.

This filters the shipping method full label and accepts two parameters, $label, the label of the shipping method, and $method, the actual method object.

To filter a specific method label, you can reference the method by its id.

You can access the method_id property of the method object.

Then set different cases in a switch statement covering the different methods you want to filter.

At the end, always return $label.

* Filter the shipping method labels and add an extra text string to the right side of the method's label.
* @param $label. The shipping method label.
* @param $method. The method object.
* @return $label. The shipping method label, whether modified or left intact.
add_filter( 'woocommerce_cart_shipping_method_full_label', 'filter_woocommerce_cart_shipping_method_full_label', 10, 2 ); 

function filter_woocommerce_cart_shipping_method_full_label( $label, $method ) { 
   // Use the condition here with $method to apply an image or text string to a specific method.      
		case 'free_shipping':
			$label = $label . '<span>FREE</span>';
		case 'flat_rate':
			$label = $label . '<span>Icon</span>';
   return $label; // Always return $label.

This is tested and works perfectly with CheckoutWC 9.0.25 (the latest version at the time of writing).

Leave a Reply

Your email address will not be published. Required fields are marked *