微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WooCommerce-如何在交付方式之前插入图标

如何解决WooCommerce-如何在交付方式之前插入图标

美好的一天,

有人可以帮我在投放方式前插入图标吗?

我使用此过滤器

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 === "napobocce" ) {
       $label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />".$label;
   } 
   if( $method->method_id == "zasilkovna" ) {
       $label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />".$label;       
   }
   if( $method->method_id == "doprava>ceska-posta>16" ) {
       $label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />".$label;       
   }
   if( $method->method_id == "doprava>geis>16" ) {
       $label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />".$label;       
   }
   return $label; 
}

这通常适用于本地接送和Zásilkovna,但不适用于最后两个。

我在输入中的值“值”处找到了与它们在一起的ID。有人知道如何帮助我吗?

还是仅使用CSS来做到这一点?

解决方法

要找出正确的$method->method_id,您可以使用

echo 'DEBUG: method id = '. $method->method_id;

所以你得到

function filter_woocommerce_cart_shipping_method_full_label( $label,$method ) {
    // Remove afterwards
    echo 'DEBUG: method id = '. $method->method_id;
    
    // Use the condition here with $method to apply the image to a specific method.      
    if( $method->method_id === "local_pickup" ) {
        $label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />" . $label;
    } elseif( $method->method_id == "zasilkovna" ) {
        $label = "<img src='https://image.flaticon.com/icons/svg/2922/2922830.svg' style='height: 30px; border-radius: 20px; margin-left: 5px; margin-right: 5px;' />" . $label;       
    }
    
    return $label; 
}
add_filter( 'woocommerce_cart_shipping_method_full_label','filter_woocommerce_cart_shipping_method_full_label',10,2 ); 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。