首页 > 解决方案 > 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 来做到这一点?

标签: phpwordpresswoocommerceiconsshipping-method

解决方案


要找出正确的$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 ); 

推荐阅读