页面刷新后,具有自定义订单状态的订单消失

时间:2021-10-21 作者:user2679476

我已根据以下链接添加了自定义订单状态:How to create a custom order status in woocommerce!

我创建的自定义订单状态为“outToDelivery”。现在,对于一个新订单,我将状态更改如下:保持-->;正在处理-->;输出交付

但是,当为特定订单设置自定义订单状态“outToDelivery”并且刷新订单页面时,订单将从订单列表中消失。

我们是否需要为最新版本的Woocommerce(5.8.0版)做些额外的工作才能使其正常工作?

1 个回复
SO网友:user2679476

糟糕的是,我在“init”hook中使用了add\\u filter()而不是add\\u action()。

以下链接是添加自定义订单状态和电子邮件通知的完美解决方案。我的Woocommerce版本是5.8.0版。

https://www.codegrepper.com/code-examples/whatever/woocommerce_email_actions

代码段如下所示:

// Add custom status to order list
add_action( \'init\', \'register_custom_post_status\', 10 );
function register_custom_post_status() {
    register_post_status( \'wc-tree\', array(
        \'label\'                     => _x( \'Waiting in tree\', \'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( \'Waiting in tree <span class="count">(%s)</span>\', \'Waiting in tree <span class="count">(%s)</span>\', \'woocommerce\' )
    ) );
}

// Add custom status to order page drop down
add_filter( \'wc_order_statuses\', \'custom_wc_order_statuses\' );
function custom_wc_order_statuses( $order_statuses ) {
    $order_statuses[\'wc-tree\'] = _x( \'Waiting in tree\', \'Order status\', \'woocommerce\' );
    return $order_statuses;
}
// Adding custom status \'tree\' to admin order list bulk 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_tree\'] = __( \'Mark Waiting in tree\', \'woocommerce\' );
    return $actions;
}

// Enable the action
add_filter( \'woocommerce_email_actions\', \'filter_woocommerce_email_actions\' );
function filter_woocommerce_email_actions( $actions ){
    $actions[] = \'woocommerce_order_status_wc-tree\';
    return $actions;
}

// Send Customer Processing Order email notification when order status get changed from "tree" to "processing"
add_action(\'woocommerce_order_status_changed\', \'custom_status_email_notifications\', 20, 4 );
function custom_status_email_notifications( $order_id, $old_status, $new_status, $order ){
    if ( $old_status == \'tree\' && $new_status == \'processing\' ) {
        // Get all WC_Email instance objects
        $wc_emails = WC()->mailer()->get_emails();
        // Sending Customer Processing Order email notification
        $wc_emails[\'WC_Email_Customer_Processing_Order\']->trigger( $order_id );
    }
}

相关推荐