如何从运输方式标签中删除运费? woocommerce

时间:2016-10-21 09:53:38

标签: wordpress woocommerce

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

enter image description here

是否有一些代码可以取消费用?

感谢。

我尝试过使用这种方法:

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;
}

1 个答案:

答案 0 :(得分:0)

这是来自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

上添加