在自定义状态下向管理员发送新订单电子邮件

Send New Order email to Admin on custom Status

我已经创建了我的自定义订单状态 待批准 作为默认订单状态,意味着如果客户从商店订购东西,它会将其置于 待批准 而不是 Processing,这是我创建自定义状态的代码:

function register_my_order_status() {
    register_post_status( 'wc-pending-approval', array(
        'label'                     => 'Pending Approval',
        'public'                    => true,
        'exclude_from_search'       => false,
        'show_in_admin_all_list'    => true,
        'show_in_admin_status_list' => true,
        'exclude_from_orders_screen'       => false,
        'add_order_meta_boxes'             => true,
        'exclude_from_order_count'         => false,
        'exclude_from_order_views'         => false,
        'exclude_from_order_webhooks'      => false,
        'exclude_from_order_reports'       => false,
        'exclude_from_order_sales_reports' => false,
        'label_count'               => _n_noop( 'Pending Approval <span class="count">(%s)</span>', 'Pending Approval <span class="count">(%s)</span>' )
    ) );
}
add_action( 'init', 'register_my_order_status' );

// Add to list of WC Order statuses
function add_my_order_statuses( $order_statuses ) {

    $new_order_statuses = array();

    // add new order status after processing
    foreach ( $order_statuses as $key => $status ) {

        $new_order_statuses[ $key ] = $status;

        if ( 'wc-pending' === $key ) {
            $new_order_statuses['wc-pending-approval'] = 'Pending Approval';
        }
    }

    return $new_order_statuses;
}
add_filter( 'wc_order_statuses', 'add_my_order_statuses' );

为了使其成为默认状态,我编辑了这个文件:

wp-content/plugins/woocommerce/includes/gateways/cod/class-wc-gateway-cod.php

public function process_payment( $order_id ) {

        $order = wc_get_order( $order_id );

        // Mark as processing (payment won't be taken until delivery)
        //$order->update_status( 'processing', __( 'Payment to be made upon delivery.', 'woocommerce' ) );
        $order->update_status( 'pending-approval', __( 'Payment to be made upon delivery.', 'woocommerce' ) );
...

如您所见,我已将默认状态(处理中)评论为 "Pending Approval"..

现在的问题是它没有向管理员和客户发送新订单电子邮件,因为它是我的自定义状态并且它是 woocommerce 的未知状态,除此之外我没有更改任何自定义状态,请在这方面帮助我..

谢谢:)

我知道这不是一个有效的解决方案,但我的问题已经解决,我所做的是:

我将默认订单状态设置为正在处理,当我发送了所有需要的电子邮件后,我将订单状态更改为我的自定义状态待批准 :P

$order->update_status( 'processing', __( 'Payment to be made upon delivery.', 'woocommerce' ) );
$order->update_status( 'pending-approval', __( 'Payment to be made upon delivery.', 'woocommerce' ) );

我的学习目的仍然需要任何有效的解决方案..

TIA