在Woocommerce管理订单列表中显示“全部”的自定义状态的订单

问题描述 投票:3回答:1

我使用此代码创建了一些自定义订单状态

 register_post_status( 'wc-arrival-shipment', array(
        'label'                     => 'Shipped but not paid',
        'public'                    => false,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'exclude_from_search'       => false,
        'label_count'               => _n_noop( 'Shipped but not paid<span class="count">(%s)</span>', 'Shipped but not paid <span class="count">(%s)</span>' )
    ) );

除了所有订单列表外,一切运行良好。它显示正确的全部计数(3)但在列表中您只能看到1个订单,并且它不会显示已更新到新的自定义订单状态的所有其他2个订单。 1个订单仅显示仅暂停的订单

php wordpress woocommerce hook-woocommerce orders
1个回答
4
投票

要解决此问题,您还需要在wc_order_statuses过滤器钩子中添加自定义顺序...

同时,将其显示在批量操作下拉列表中会很有用。

完整的代码:

// Add custom status to order list
add_action( 'init', 'register_custom_post_status', 10 );
function register_custom_post_status() {
    register_post_status( 'wc-arrival-shipment', array(
        'label'                     => _x( 'Shipped but not paid', 'Order status', 'woocommerce' ),
        'public'                    => false,
        'exclude_from_search'       => false,
        'show_in_admin_status_list' => true,
        'show_in_admin_all_list'    => true,
        'label_count'               => _n_noop( 'Shipped but not paid<span class="count">(%s)</span>', 'Shipped but not paid <span class="count">(%s)</span>' )
    ) );
}

// Add custom status to order edit page drop down (and displaying orders with this custom status in the list)
add_filter( 'wc_order_statuses', 'custom_wc_order_statuses' );
function custom_wc_order_statuses( $order_statuses ) {
    $order_statuses['wc-arrival-shipment'] = _x( 'Shipped but not paid', 'Order status', 'woocommerce' );
    return $order_statuses;
}

// Adding custom status  to admin order list bulk actions dropdown
add_filter( 'bulk_actions-edit-shop_order', 'custom_dropdown_bulk_actions_shop_order', 20, 1 );
function custom_dropdown_bulk_actions_shop_order( $actions ) {
    $actions['mark_arrival-shipment'] = __( 'Mark Shipped but not paid', 'woocommerce' );
    return $actions;
}

代码位于活动子主题(或活动主题)的function.php文件中。经过测试和工作。

© www.soinside.com 2019 - 2024. All rights reserved.