在Woocommerce 3中更改送货方式标签名称 [英] Changing shipping method label names in Woocommerce 3
问题描述
我已经将USPS的两个运输选项添加到了我的Wordpress网站:priority mail
和first-class package service
.这些选项分别在购物车页面和结帐页面上显示为一流包裹服务" 和优先邮件" .
我发现标题都有些笨重,并且想将它们分别更改为在购物车页面和结帐页面上分别显示为标准"和优先".
要实现此目的,我需要添加什么代码的任何想法?
更新:您的标签名称不正确(还添加了基于方法ID的替代方法) >
下面的代码将允许您更改/重命名您的运输方式显示的标签名称.下面有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文件中.经过测试并可以正常工作.
您应该需要刷新运输缓存:
1)首先,此代码已经保存在您的function.php文件中.
2)在运送设置"中,输入运送区域并禁用运输方式和保存".然后重新启用该 Shipping Method (发货方式)并保存". 您已完成.
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文件中.经过测试并可以正常工作.
您应该需要刷新运输缓存:
1)首先,此代码已经保存在您的function.php文件中.
2)在运送设置"中,输入运送区域并禁用运输方式和保存".然后重新启用该 Shipping Method (发货方式)并保存". 您已完成.
I've added two shipping options from USPS to my Wordpress site: priority mail
and first-class package service
. The options are displayed as "first-class package service" and "priority mail", respectively, on both the cart and the checkout pages.
I find the titles both a bit bulky, and would like to change them to read "standard" and "priority", respectively, on both the cart and checkout pages.
Any ideas as to what code I would need to add to accomplish this?
Update: Your labels names where not correct (Also added alternative based on method IDs)
The code below will allow you to change/rename your shipping method displayed label names. Below there is 2 Alternatives:
1) Based on Shipping Wethod label name:
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;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
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) Based on Shipping Method IDs:
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;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
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.
这篇关于在Woocommerce 3中更改送货方式标签名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!