Woocommerce自定义订单状态不显示

时间:2020-03-06 12:49:02

标签: php wordpress woocommerce hook-woocommerce orders

我一直试图在woocommerce中添加自定义订单状态已发货

这是代码

function add_awaiting_shippped_to_order_statuses( $order_statuses ) {

        $new_order_statuses = array();

        // add new order status before processing
        foreach ($order_statuses as $key => $status) {
            $new_order_statuses[$key] = $status;
            if ('wc-processing' === $key) {
                $new_order_statuses['wc-order-shipped'] = __('Shipped', 'woocommerce' );
            }
        }

        return $new_order_statuses;


    }
  function register_shipped_status() {


            register_post_status( 'wc-order-shipped', array(
                'label'                     => _x( 'Shipped', 'Order status', 'woocommerce' ),
                'public'                    => true,
                'exclude_from_search'       => false,
                'show_in_admin_all_list'    => true,
                'show_in_admin_status_list' => true,
                'label_count'               => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped<span class="count">(%s)</span>', 'woocommerce' )
            ) );


    }

add_action( 'init', array( $plugin_admin_meta_box, 'register_shipped_status') );

add_filter( 'wc_order_statuses', array( $plugin_admin_meta_box, 'add_awaiting_shippped_to_order_statuses') );

在woocommerce中,运输状态随处可见,并且运行正常

enter image description here

每当我更改要发送的订单状态时,订单就会成功更新

现在的问题是已发货订单未显示在订单表中

enter image description here

1 个答案:

答案 0 :(得分:0)

以下方法可在自定义插件中添加功能性自定义订单状态:

// Register new custom order status
function register_shipped_status() {
    register_post_status( 'wc-order-shipped', array(
        'label'                     => _x( 'Shipped', 'Order status', 'woocommerce' ),
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'label_count'               => _n_noop( 'Shipped <span class="count">(%s)</span>', 'Shipped<span class="count">(%s)</span>', 'woocommerce' )
    ) );
}

// Add new custom order status to list of WC Order statuses
function add_awaiting_shippped_to_order_statuses( $order_statuses ) {
    $new_order_statuses = array();

    // add new order status before processing
    foreach ($order_statuses as $key => $status) {
        $new_order_statuses[$key] = $status;
        if ('wc-processing' === $key) {
            $new_order_statuses['wc-order-shipped'] = _x( 'Shipped', 'Order status', 'woocommerce' );
        }
    }
    return $new_order_statuses;
}

// Adding custom status to admin order list bulk actions dropdown
function custom_dropdown_bulk_actions_shop_order( $actions ) {
    $new_actions = array();

    // Add new order status before processing
    foreach ($actions as $key => $action) {
        $new_actions[$key] = $action;
        if ('mark_processing' === $key) {
            $actions['mark_order-shipped'] = __( 'Mark Shipped', 'woocommerce' );
        }
    }

    return $actions;
}

add_action( 'init', array($plugin_admin_meta_box, 'register_shipped_status') );
add_filter( 'wc_order_statuses', array($plugin_admin_meta_box, 'add_awaiting_shippped_to_order_statuses' );
add_filter( 'bulk_actions-edit-shop_order', array($plugin_admin_meta_box, 'custom_dropdown_bulk_actions_shop_order'), 20, 1 );

enter image description here