2017-07-28 98 views
1

在WooCommerce中,当客户从购物车结账并提交订单时,如果未处理付款,则会将订单设置为“待处理”付款。管理员没有收到任何关于的电子邮件。在WooCommerce中向管理员发送挂单状态的电子邮件通知

我想发送一封电子邮件给管理这种订单。我该怎么做?

+0

woocommerce有钩的很多,我敢肯定,他们中的一个可能会有所帮助:https://开头docs.woocommerce.com/wc-apidocs/hook-docs.html – WheatBeak

回答

0

UPDATE

此代码将在所有可能的情况下被解雇时,新订单获得挂起状态,将自动触发一个“新秩序”电子邮件通知:

// New order notification only for "Pending" Order status 
add_action('woocommerce_new_order', 'pending_new_order_notification', 20, 1); 
function pending_new_order_notification($order_id) { 

    // Get an instance of the WC_Order object 
    $order = wc_get_order($order_id); 

    // Only for "pending" order status 
    if(! $order->has_status('pending')) return; 

    // Send "New Email" notification (to admin) 
    WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger($order_id); 
} 

代码进入你活动的儿童主题(或主题)的function.php文件,或者在任何插件文件中。

此代码已经过测试,适用于WooCommerce版本2.6.x和3+。



一个更具个性化版本的代码(如果需要)的,这将使挂单更为明显

// New order notification only for "Pending" Order status 
add_action('woocommerce_new_order', 'pending_new_order_notification', 20, 1); 
function pending_new_order_notification($order_id) { 
    // Get an instance of the WC_Order object 
    $order = wc_get_order($order_id); 

    // Only for "pending" order status 
    if(! $order->has_status('pending')) return; 

    // Get an instance of the WC_Email_New_Order object 
    $wc_email = WC()->mailer()->get_emails()['WC_Email_New_Order']; 

    ## -- Customizing Heading, subject (and optionally add recipients) -- ## 
    // Change Subject 
    $wc_email->settings['subject'] = __('{site_title} - New customer Pending order ({order_number}) - {order_date}'); 
    // Change Heading 
    $wc_email->settings['heading'] = __('New customer Pending Order'); 
    // $wc_email->settings['recipient'] .= ',[email protected]'; // Add email recipients (coma separated) 

    // Send "New Email" notification (to admin) 
    $wc_email->trigger($order_id); 
} 

代码放在您的活动子function.php文件主题(或主题)或任何插件文件。

此代码已经过测试,适用于WooCommerce版本2.6.x和3+。

在这个版本中,你可以自定义邮件的标题,主题,添加收件人...

+0

亲爱的这个功能看起来很棒,但它不适合我。我使用的是wp 4.8版本。 –

+0

@burhanjamil **我已经更新了我的答案**,请尝试。我已经改变了这个挂钩,现在它可以在任何情况下用于“挂单状态”......现在代码更有效,更紧凑,更轻便。有两个版本,一个只发送默认的“新订单”通知,另一个将允许一些自定义(如果需要)... – LoicTheAztec

相关问题