为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
心有法竹 2023-10-15 16:47:38
基于这个问题,我在我正在建立的商店的运输方式中添加了一些图标。我通过使用以下代码使用了 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; }我想改变一件事,但我不知道如何去做。我希望图标显示在送货方式名称旁边。不,它在下面。关于如何解决这个问题有什么想法吗?
查看完整描述

1 回答

?
qq_遁去的一_1

TA贡献1725条经验 获得超7个赞

您需要更改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 文件中。经过测试并有效。


查看完整回答
反对 回复 2023-10-15
  • 1 回答
  • 0 关注
  • 92 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号