在Woocommerce管理员订单列表中显示具有自定义"all"状态的订单



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

 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 个订单,仅显示处于暂停状态

要解决此问题,您还需要在过滤器钩子中添加自定义订单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;
}

代码进入函数.php活动子主题(或活动主题(的文件。经过测试并工作。

相关内容

  • 没有找到相关文章

最新更新