【问题标题】:Hide orders (table rows) in WooCommerce admin order list based on order status根据订单状态在 WooCommerce 管理订单列表中隐藏订单(表格行)
【发布时间】:2021-06-21 10:43:39
【问题描述】:

我需要在 WooCommerce 管理订单列表中隐藏具有特定状态的订单。 (wp-admin/edit.php?post_type=shop_order)。

CSS 不会像用户只显示 20 行一样工作,可能有一个页面没有结果,因为许多订单可能具有这种状态。

我尝试了以下功能:

add_action('wc_order_statuses', 'my_statuses');

function my_statuses($order_statuses) {

    unset($order_statuses['wc-my_status']);
    return $order_statuses;
}

...但这与我在感谢页面上的功能(如下)发生冲突,该功能不再将订单状态更改为我的自定义状态,可能是因为上述功能将其删除。

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' );
      }
}

有没有简单的方法可以从 WooCommerce 管理面板的订单列表中隐藏带有 my_status 的订单?

【问题讨论】:

  • wc_order_statuses 操作钩子用于在 ​​下拉菜单@单个订单中添加/删除订单状态,而不是从 WooCommerce 管理订单列表中隐藏订单状态,也可以不影响woocommerce_thankyou钩子
  • 嗯,但我测试了这个功能激活/不激活,它确实隐藏了管理面板中的订单:link 功能激活 - 订单不显示(正确)但thankyou_hook没有改变我的自定义状态 merchdesign link 的新订单,功能未激活 - 订单显示在管理列表中(不正确),但thankyou_hook 正在将新订单更改为我的自定义状态 刚刚做了一个新测试,使订单功能处于活动/非活动状态,并且它似乎确实以某种方式影响它

标签: php wordpress woocommerce backend orders


【解决方案1】:

在 WooCommerce 管理订单列表中隐藏包含特定订单状态的行。您可以使用parse_query 操作挂钩。

所以你得到:

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 );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 2021-04-08
    • 2023-01-25
    • 2017-07-22
    • 1970-01-01
    相关资源
    最近更新 更多