简体   繁体   English

根据订单状态隐藏WooCommerce admin订单列表中的订单(表格行)

[英]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.

相关问题 在WooCommerce管理订单页面的状态下拉菜单中隐藏订单状态 - Hide order status in the status dropdown on WooCommerce admin orders page 在WooCommerce 3.3的管理订单列表中显示回购订单注释 - Display back Order Notes in Admin orders list on WooCommerce 3.3 在Woocommerce管理订单中显示列出了已完成订单的用户名 - Show in Woocommerce admin orders list the username that has completed the order WooCommerce 管理员订单列表自定义列,其中包含发送给客户的订单备注 - WooCommerce admin orders list custom column with order notes sent to customer 将客户email和“订单”栏中的电话添加到Woocommerce的管理订单列表中 - Add customer email and phone in "Order" column to admin orders list on Woocommerce 在 WooCommerce admin Orders List 列显示复合订单数据 - Display composite order data in WooCommerce admin Orders List column "WooCommerce 管理订单列表中用于自定义订单状态的操作按钮问题" - Issue with action button in WooCommerce admin order list for custom order status 为Woocommerce管理员订单添加自定义订单状态的特定操作按钮图标 - Add specific action button icon for custom order status to Woocommerce admin orders 自定义 PHP 剪辑器,用于向管理员发送电子邮件通知,以了解 WooCommerce 中的待处理订单状态,导致已处理订单的电子邮件重复 - Custom PHP snipper for email notification to the admin for pending order status in WooCommerce causing duplicated emails for processed orders WooCommerce - 在管理员顺序列表中重命名批量操作完成状态 - WooCommerce - Renaming bulk actions complete status in admin order list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM