我想要更改显示在我的商店结帐中基于产品的运输类显示的运输方法标题。
例如:
船运方法标题目前是统一费率,我有两个产品:
遗憾的是,我不得不使用类来完成我的运输,这样替代方法就不能工作了。
任何帮助都将不胜感激。
发布于 2018-06-25 16:48:32
以下代码将根据您的“脆弱”运输级别重命名您的发货统一费率:
您可能必须在“传送选项”选项卡下的一般传送设置中“启用调试模式”,以禁用临时传送缓存。
守则:
add_filter('woocommerce_package_rates', 'change_shipping_method_name_based_on_shipping_class', 50, 2);
function change_shipping_method_name_based_on_shipping_class($rates, $package){
// HERE set the shipping class for "Fragile"
$shipping_class_id = 64;
$found = false;
// Check for the "Fragile" shipping class in cart items
foreach( $package['contents'] as $cart_item ) {
if( $cart_item['data']->get_shipping_class_id() == $shipping_class_id ){
$found = true;
break;
}
}
// Loop through shipping methods
foreach ( $rates as $rate_key => $rate ) {
// Change "Flat rate" Shipping method label name
if ( 'flat_rate' === $rate->method_id ) {
if( $found )
$rates[$rate_key]->label = __( 'Fragile shipping', 'woocommerce' );
else
$rates[$rate_key]->label = __( 'Standard shipping', 'woocommerce' );
}
}
return $rates;
}代码在您的活动子主题(或活动主题)的function.php文件中。测试和工作。
不要忘记在传送设置中重新启用“启用调试模式”选项。
https://stackoverflow.com/questions/51026568
复制相似问题