根据 WooCommerce 编辑订单页面中的订单状态在下拉列表中隐藏订单状态
Hide order statuses in dropdown based on order status in WooCommerce edit order page
我想在特定情况下隐藏 WooCommerce 订单状态下拉列表中的订单状态:
- 如果状态为待付款隐藏完成
- 如果状态正在处理隐藏待付款
我还想在订单概览列表中显示所有这些订单状态。
我能找到的就是完全取消设置订单状态:
function so_39252649_remove_processing_status ($statuses) {
if (isset($statuses['wc-processing'])) {
unset($statuses['wc-processing']);
}
return $statuses;
}
add_filter('wc_order_statuses', 'so_39252649_remove_processing_status');
但这当然也会将其从订单概览列表中删除,我只想将其隐藏在订单编辑页面的下拉列表中,但我找不到用于此的挂钩。
jQuery是我唯一的选择吗?
你可以使用下面的注释,在代码中添加解释。
所以你得到:
// Admin order edit page: order status dropdown
function filter_wc_order_statuses( $order_statuses ) {
global $post, $pagenow;
// Target edit pages
if( $pagenow === 'post.php' && isset($_GET['post']) && $_GET['action'] == 'edit' && get_post_type($_GET['post']) === 'shop_order' ) {
// Get ID
$order_id = $post->ID;
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// Is a WC order
if ( is_a( $order, 'WC_Order' ) ) {
// Get current order status
$order_status = $order->get_status();
// Compare
if ( $order_status == 'pending' ) {
unset( $order_statuses['wc-completed'] );
} elseif ( $order_status == 'processing' ) {
unset( $order_statuses['wc-pending'] );
}
}
}
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'filter_wc_order_statuses', 10, 1 );
我想在特定情况下隐藏 WooCommerce 订单状态下拉列表中的订单状态:
- 如果状态为待付款隐藏完成
- 如果状态正在处理隐藏待付款
我还想在订单概览列表中显示所有这些订单状态。
我能找到的就是完全取消设置订单状态:
function so_39252649_remove_processing_status ($statuses) {
if (isset($statuses['wc-processing'])) {
unset($statuses['wc-processing']);
}
return $statuses;
}
add_filter('wc_order_statuses', 'so_39252649_remove_processing_status');
但这当然也会将其从订单概览列表中删除,我只想将其隐藏在订单编辑页面的下拉列表中,但我找不到用于此的挂钩。
jQuery是我唯一的选择吗?
你可以使用下面的注释,在代码中添加解释。
所以你得到:
// Admin order edit page: order status dropdown
function filter_wc_order_statuses( $order_statuses ) {
global $post, $pagenow;
// Target edit pages
if( $pagenow === 'post.php' && isset($_GET['post']) && $_GET['action'] == 'edit' && get_post_type($_GET['post']) === 'shop_order' ) {
// Get ID
$order_id = $post->ID;
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// Is a WC order
if ( is_a( $order, 'WC_Order' ) ) {
// Get current order status
$order_status = $order->get_status();
// Compare
if ( $order_status == 'pending' ) {
unset( $order_statuses['wc-completed'] );
} elseif ( $order_status == 'processing' ) {
unset( $order_statuses['wc-pending'] );
}
}
}
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'filter_wc_order_statuses', 10, 1 );