我正在尝试根据购物车中是否有任何产品有附加功能来更改发货标签。
为此,我使用How can I modify a Woocommerce shipping label
答案代码,有一些变化,以满足我的需要。
HTML:
Standard Shipping (2-3 days): 3,95€所以标签标准发货(2-3天)必须显示自定义发货(4-6天)如果满足某个条件(在本例中:字段自定义_文本不为空)。
functions.php:
//Change Standard Shipping Label if product is customized
add_filter( 'woocommerce_cart_shipping_method_full_label', 'change_shipping_label', 10, 2 );
function change_shipping_label( $full_label, $method ){
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if ( !empty( $cart_item['custom_text'] ) ) {
$full_label = str_replace( "Standard Shipping (2-3 days)", "Shipping with customization (4-6 days)", $full_label );
}
}
return $full_label;
}这是一次成功。如果满足条件,标签将在结帐前更改为Shipping with customization (4-6天)。
但是,标签更改不适用于结帐后(感谢页面和电子邮件,它显示原始的“标准发货(2-3天)”。
我可以在感谢页面和电子邮件上显示此标签更改吗?
发布于 2021-02-26 23:25:15
更新2
根据提供的代码和信息,要更改订单上的特定发货标签,请使用发货费率Id来确定所需的发货方式:
add_action( 'woocommerce_checkout_create_order_shipping_item', 'action_wc_checkout_create_order_shipping_item', 10, 4 );
function action_wc_checkout_create_order_shipping_item( $item, $package_key, $package, $order ) {
// Targeting "flat_rate:5" by its instance ID
if( $item->get_instance_id() == 5 ) {
$item->set_method_title( "Shipping with customization (4-6 days)" );
}
}代码放在活动子主题(或活动主题)的functions.php文件中。经过测试,效果良好。
相关信息: Change specific shipping method title on WooCommerce orders after checkout
https://stackoverflow.com/questions/66385332
复制相似问题