Adding custom icons to the shipping options in Woo

2020-08-01 06:32发布

I want to add icons to the shipping options in Woocommerce Cart and Checkout.

For example in the "local pickup" option I want to show a little store icon beside the option just like this: https://ibb.co/jz0jJgk

I tried to do add this code in the title of the "local pickup" option in the Woocommerce>settings>shipping options but it doesn't show the custom store icon that I have.

Local Pickup <img src="examplesite.com/media/store_icon.png" alt="local store icon">

If this is possible... what code do I need to add at functions.php or in which file?

Thank you for reading.

UPDATE:

So far I have been using this (a useful tip provided by @Jainil)

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 ) { 
        $shipping_method_id = ['flat_rate:19'];
        $label .= 'class="shipping_method"'('<img src="https://site.local/wp-content/uploads/2019/10/icon_store.png">', 'woocommerce');// Use the condition here with $method to apply the image to a specific method.      

    return $label; 
}

But it shows the icon in every shipping option available https://ibb.co/9ZJKVB8

I just want to show the icon in specific Local Pickup option.

1条回答
Lonely孤独者°
2楼-- · 2020-08-01 07:06

Use the woocommerce_cart_shipping_method_full_label filter.

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 the image to a specific method.      

   if( $method->method_id == "flat_rate" ) {
       $label = $label."Your Icon Image";
   } else if( $method->method_id == "local_pickup" ) {
       $label = $label."Your Icon Image";       
   }
   return $label; 
}
查看更多
登录 后发表回答