【问题标题】:How to remove shipping cost from shipping method label? woocommerce如何从运输方式标签中删除运输成本? woocommerce
【发布时间】:2016-10-21 09:53:38
【问题描述】:

我正在尝试从运输方式标签中删除运费。

是否有一些代码可以消除成本?

谢谢。

我试过用这个方法:

add_filter( 'woocommerce_cart_shipping_method_full_label', 'remove_local_pickup_free_label', 10, 2 );
  function remove_local_pickup_free_label($full_label, $method){
     $full_label = str_replace("USD","HKD",$full_label);
 return $full_label;
}

解决方案:

 add_filter( 'woocommerce_cart_shipping_method_full_label','remove_local_pickup_free_label', 10, 2 );
 function remove_local_pickup_free_label($full_label, $method){
   $full_label = substr( $full_label, 0, strpos( $full_label, ':'));
   return $full_label;
}

【问题讨论】:

  • 找到类并使用自定义 css 插件显示:无
  • 它不能使用css来删除它。由于成本与送货地址有关。如果我用css删除它,所有的地址都会被删除...

标签: wordpress woocommerce


【解决方案1】:

这是来自 Woocommerce 支持页面

/**
 * Remove shipping name from the label in Cart and Checkout pages
 */
add_filter( 'woocommerce_cart_shipping_method_full_label', 'wc_custom_shipping_labels', 10, 2 );
function wc_custom_shipping_labels( $label, $method ) {
    if ( $method->cost > 0 ) {
        if ( WC()->cart->tax_display_cart == 'excl' ) {
            $label = wc_price( $method->cost );
            if ( $method->get_shipping_tax() > 0 && WC()->cart->prices_include_tax ) {
                $label .= ' <small>' . WC()->countries->ex_tax_or_vat() . '</small>';
            }
        } else {
            $label = wc_price( $method->cost + $method->get_shipping_tax() );
            if ( $method->get_shipping_tax() > 0 && ! WC()->cart->prices_include_tax ) {
                $label = ' <small>' . WC()->countries->inc_tax_or_vat() . '</small>';
            }
        }
    }

    return $label;
}

您可以修改上述代码并使用它来隐藏标签中的实际价格。不要忘记使用子主题并将其添加到functions.php

【讨论】:

    猜你喜欢
    • 2021-01-24
    • 1970-01-01
    • 2019-04-18
    • 2016-03-20
    • 1970-01-01
    • 2016-09-27
    • 2021-12-10
    • 2021-02-28
    • 1970-01-01
    相关资源
    最近更新 更多