仅在订单使用免费送货时,我才尝试在已收到订单(谢谢)页面上添加一条消息。该消息可以代替标准的“谢谢...”消息,也可以补充。
这是我正在使用的代码。它基于以下答案:Customize Order received page based on shipping method in WooCommerce
//add message to order received if outside delivery area
add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $thankyou_text, $order ) {
if ( is_wc_endpoint_url( 'order-received' ) ) {
global $wp;
$order_id = absint( $wp->query_vars['order-received'] );
$order_key = isset( $_GET['key'] ) ? wc_clean( $_GET['key'] ) : '';
$method_title_names = array();
if( in_array( 'Free shipping', $method_title_names ) ) {
return sprintf( __("%s <div class=\"outside-delivery-checkout\"><b>PLEASE NOTE:</b><br />Your shipping destination is outside of our normal delivery area. Our team will call you to calculate an additional fuel surcharge.</div>", "woocommerce"),
$thankyou_text
);
}
}
return $thankyou_text;
}
我无法使其正常工作,也不知道出了什么问题。任何帮助将不胜感激。
答案 0 :(得分:1)
您只需要以下(其中“免费送货”是您的免费送货方式的名称)
:add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $text, $order ) {
if( $order->get_shipping_method() == 'Free shipping' ) {
$text .= ' <div class=\"outside-delivery-checkout\"><strong>'. __("PLEASE NOTE", "woocommerce") . ':</strong><br />'.__("Your shipping destination is outside of our normal delivery area. Our team will call you to calculate an additional fuel surcharge.", "woocommerce") . '</div>';
}
return $text;
}
类似:代码进入活动子主题(或活动主题)的function.php文件。经过测试和工作。
Customize Order received page based on shipping method in WooCommerce