更改添加到运输方式中的图标的位置Woocommcerce

问题描述

基于this question,我在正在建立的商店的送货方式中添加了一些图标。我通过以下代码使用了png图片:

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.('<img src="https://www.website-link/wp-content/uploads/2020/08/002-truck.png">');
} else if( $method->method_id == "local_pickup" ) {
   $label = $label.('<img src="https://www.website-link/wp-content/uploads/2020/08/001- discount.png">');       
} 
return $label; 
}

我想改变一件事,但我不知道该怎么做。我希望图标显示在送货方式名称旁边。不,它在下面。关于如何解决此问题的任何想法?

先谢谢了。 瓦斯科

解决方法

您需要在子主题的display文件中更改图标的style.css css属性:

#shipping_method label > img {
    display: inline-block;
}

因此,您可以在代码中对样式进行硬编码的代码中对其进行测试:

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 ) {
    $style = ' style="display:inline-block;"'; // Style applied to the thumbnails
    
    // Use the condition here with $method to apply the image to a specific method.      
    if( $method->method_id == "flat_rate" ) {
       $label = ' <img src="https://www.website-link/wp-content/uploads/2020/08/002-truck.png"'.$style.'> ' . $label;
    } else if( $method->method_id == "local_pickup" ) {
       $label = ' <img src="https://www.website-link/wp-content/uploads/2020/08/001-discount.png"'.$style.'> ' . $label;      
    } 
    return $label; 
}

代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...