根据订单状态更改 WooCommerce 感谢页面标题
Change WooCommerce thankyou page title based on order status
正在尝试根据特定的订单状态更改感谢页面的标题,方法是组合过滤器和操作,如下所示:
add_action( 'woocommerce_thankyou', 'order_thank_you_status' );
function order_thank_you_status( $order_id ){
// Get an instance of the `WC_Order` Object
$order = wc_get_order( $order_id );
// Get the order number
$order_number = $order->get_order_number();
// Get the order status name
$status_name = wc_get_order_status_name( $order->get_status() );
// Get the order key
$test_order_key = $order->get_order_key();
if ( $order->has_status('on-hold') || $order->has_status('mockup-requested') || $order->has_status('mockup-sent')|| $order->has_status('mockup-approved')) {
echo 'helllo world';
add_filter( 'the_title', 'woo_title_order_received', 10, 2 );
function woo_title_order_received( $title, $id ) {
if ( function_exists( 'is_order_received_page' ) &&
is_order_received_page() && get_the_ID() === $id ) {
$title = "Mockup request received";
}
return $title;
}
}
}
但我尝试了多种方法将两者结合起来,但都没有成功。
您可以使用以下方法根据订单状态更改“已收到订单”页面标题:
add_action( 'the_title', 'change_order_received_page_title_based_on_order_status' );
function change_order_received_page_title_based_on_order_status( $title ){
if ( is_wc_endpoint_url('order-received') && $title === 'Order received' ) {
global $wp;
$targeted_statuses = array('on-hold', 'mockup-requested', 'mockup-sent', 'mockup-approved' );
// Get an instance of the `WC_Order` Object
$order = wc_get_order( absint($wp->query_vars['order-received']) );
if ( is_a( $order, 'WC_Order' ) && in_array( $order->get_status(), $targeted_statuses ) ) {
return __("Mockup request received", "woocommerce");
}
}
return $title;
}
代码进入活动 child 主题(或活动主题)的 functions.php 文件。已测试并有效。
正在尝试根据特定的订单状态更改感谢页面的标题,方法是组合过滤器和操作,如下所示:
add_action( 'woocommerce_thankyou', 'order_thank_you_status' );
function order_thank_you_status( $order_id ){
// Get an instance of the `WC_Order` Object
$order = wc_get_order( $order_id );
// Get the order number
$order_number = $order->get_order_number();
// Get the order status name
$status_name = wc_get_order_status_name( $order->get_status() );
// Get the order key
$test_order_key = $order->get_order_key();
if ( $order->has_status('on-hold') || $order->has_status('mockup-requested') || $order->has_status('mockup-sent')|| $order->has_status('mockup-approved')) {
echo 'helllo world';
add_filter( 'the_title', 'woo_title_order_received', 10, 2 );
function woo_title_order_received( $title, $id ) {
if ( function_exists( 'is_order_received_page' ) &&
is_order_received_page() && get_the_ID() === $id ) {
$title = "Mockup request received";
}
return $title;
}
}
}
但我尝试了多种方法将两者结合起来,但都没有成功。
您可以使用以下方法根据订单状态更改“已收到订单”页面标题:
add_action( 'the_title', 'change_order_received_page_title_based_on_order_status' );
function change_order_received_page_title_based_on_order_status( $title ){
if ( is_wc_endpoint_url('order-received') && $title === 'Order received' ) {
global $wp;
$targeted_statuses = array('on-hold', 'mockup-requested', 'mockup-sent', 'mockup-approved' );
// Get an instance of the `WC_Order` Object
$order = wc_get_order( absint($wp->query_vars['order-received']) );
if ( is_a( $order, 'WC_Order' ) && in_array( $order->get_status(), $targeted_statuses ) ) {
return __("Mockup request received", "woocommerce");
}
}
return $title;
}
代码进入活动 child 主题(或活动主题)的 functions.php 文件。已测试并有效。