在 Woocommerce 3 中更改运输方式标签名称

Changing shipping method label names in Woocommerce 3

我在我的 Wordpress 网站上添加了两个从 USPS 寄送的选项:priority mailfirst-class package service。这些选项在购物车和结帐页面上分别显示为 "first-class package service""priority mail"

我发现这两个标题都有些笨重,想将它们更改为在购物车和结帐页面上分别显示为 "standard" 和 "priority"。

关于我需要添加什么代码来完成这个有什么想法吗?

更新: 您的标签名称不正确 (还添加了基于方法 ID 的替代方法)

下面的代码将允许您 change/rename 您的送货方式显示标签名称。下面有 2 个备选方案:

1) 基于运输方式标签名称:

add_filter( 'woocommerce_package_rates', 'change_shipping_methods_label_names', 20, 2 );
function change_shipping_methods_label_names( $rates, $package ) {

    foreach( $rates as $rate_key => $rate ) {

        if ( __( 'First-Class Package Service', 'woocommerce' ) == $rate->label )
            $rates[$rate_key]->label = __( 'Standard', 'woocommerce' ); // New label name

        if ( __( 'Priority Mail', 'woocommerce' ) == $rate->label )
            $rates[$rate_key]->label = __( 'Priority', 'woocommerce' ); // New label name
    }

    return $rates;
}

代码进入您的活动子主题(或活动主题)的 function.php 文件。 已测试并有效。

You should need to refresh the shipping caches:
1) First this code is already saved on your function.php file.
2) In Shipping settings, enter in a Shipping Zone and disable a Shipping Method and "save". Then re-enable that Shipping Method and "save". You are done.


2) 基于送货方式 ID:

add_filter( 'woocommerce_package_rates', 'change_shipping_methods_label_names', 10, 2 );
function change_shipping_methods_label_names( $rates, $package ) {

    foreach( $rates as $rate_key => $rate ) {

        if ( 'wc_services_usps:1:first_class_package' == $rate_key )
            $rates[$rate_key]->label = __( 'USPS first class', 'woocommerce' ); // New label name

        if ( 'wc_services_usps:1:pri' == $rate_key )
            $rates[$rate_key]->label = __( 'USPS priority', 'woocommerce' ); // New label name
    }
    return $rates;
}

代码进入您的活动子主题(或活动主题)的 function.php 文件。 已测试并有效。

You should need to refresh the shipping caches:
1) First this code is already saved on your function.php file.
2) In Shipping settings, enter in a Shipping Zone and disable a Shipping Method and "save". Then re-enable that Shipping Method and "save". You are done.