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

时间:2018-04-20 07:21:23

标签: php wordpress woocommerce hook-woocommerce orders

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

from rest_framework import viewsets
from .serializers import RegisterSerializer
from rest_framework.response import Response
import json

class RegisterViewSet(viewsets.ModelViewSet):
    queryset = ''
    serializer_class = RegisterSerializer
    def create(self,request, *args, **kwargs):
        print(json.loads(request.body))
        serializer_class = RegisterSerializer(json.loads(request.body))
        return Response(serializer_class)

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

1 个答案:

答案 0 :(得分: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文件中。经过测试和工作。