[英]Hide orders (table rows) in WooCommerce admin order list based on order status
I need to hide orders with a specific status in the WooCommerce admin orders list.我需要在 WooCommerce 管理员订单列表中隐藏具有特定状态的订单。 ( wp-admin/edit.php?post_type=shop_order ). ( wp-admin/edit.php?post_type=shop_order )。
CSS won't work as if the user only shows 20 rows, there might be a page with no results as many orders might have this status. CSS 将不起作用,因为用户只显示 20 行,可能有一个页面没有结果,因为许多订单可能具有此状态。
I tried the following function:我尝试了以下 function:
add_action('wc_order_statuses', 'my_statuses');
function my_statuses($order_statuses) {
unset($order_statuses['wc-my_status']);
return $order_statuses;
}
...but that made conflict with my function (below) on the Thank you page which no longer changed the order status to my custom status, probably because the function mentioned above removes it. ...但这与我在感谢页面上的 function(如下)发生冲突,该页面不再将订单状态更改为我的自定义状态,可能是因为上面提到的 function 将其删除。
add_action( 'woocommerce_thankyou', 'woocommerce_thankyou_change_order_status', 10, 1 );
function woocommerce_thankyou_change_order_status( $order_id ){
if( // my custom code ) {
$order->update_status( 'my_status' );
}
}
Is there no easy way to hide orders with my_status from the order list in WooCommerce admin panel?有没有简单的方法可以从 WooCommerce 管理面板的订单列表中隐藏带有my_status的订单?
To hide row(s) containing a specific order status, in WooCommerce admin order list.要隐藏包含特定订单状态的行,请在 WooCommerce 管理员订单列表中。 You can use the parse_query
action hook.您可以使用parse_query
操作挂钩。
So you get:所以你得到:
function action_parse_query( $query ) {
global $pagenow;
// Your order status to hide, must start with 'wc-'
$hide_order_status = 'wc-completed';
// Initialize
$query_vars = &$query->query_vars;
// Only on WooCommerce admin order list
if ( $pagenow == 'edit.php' && $query_vars['post_type'] == 'shop_order' ) {
// Finds whether a variable is an array
if ( is_array( $query_vars['post_status'] ) ) {
// Searches the array for a given value and returns the first corresponding key if successful
if ( ( $key = array_search( $hide_order_status, $query_vars['post_status'] ) ) !== false ) {
unset( $query_vars['post_status'][$key] );
}
}
}
}
add_action( 'parse_query', 'action_parse_query', 10, 1 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.