如何解决更改添加到运输方式中的图标的位置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文件中。经过测试,可以正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。