问题描述
美好的一天,
有人可以帮我在投放方式前插入图标吗?
我使用此过滤器
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 );