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

WooCommerce - How to insert icons before delivery method

美好的一天,

谁能帮我看看如何在交付方式前插入图标?

我用这个过滤器

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 通常有效,但对最后两个无效。

我在输入的值“value”处找到了我的 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 );