Я пытаюсь отправить электронное письмо клиенту, когда заказ отменяется. По умолчанию woocommerce отправляет это письмо только администратору сайта. Этот код решил проблему для связанных сообщений в Интернете:
function wc_cancelled_order_add_customer_email( $recipient, $order ){
return $recipient . ',' . $order->billing_email;
}
add_filter( 'woocommerce_email_recipient_cancelled_order', 'wc_cancelled_order_add_customer_email', 10, 2 );
add_filter( 'woocommerce_email_recipient_failed_order', 'wc_cancelled_order_add_customer_email', 10, 2 );
Однако, похоже, woocommerce полностью удалила эти фильтры. Есть ли способ сделать это?
Заранее спасибо!
В этой настраиваемой функции, зацепившейся за woocommerce_order_status_changed
действия woocommerce_order_status_changed
, я нацеливаю "отмененные" и "неудачные" заказы, отправляя соответствующее уведомление по электронной почте клиенту (поскольку администратор получит его на его стороне автоматическими уведомлениями WooCommerce):
add_action('woocommerce_order_status_changed', 'custom_send_email_notifications', 10, 4 );
function custom_send_email_notifications( $order_id, $old_status, $new_status, $order ){
if ( $new_status == 'cancelled' || $new_status == 'failed' ){
$wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects instances
$customer_email = $order->get_billing_email(); // The customer email
}
if ( $new_status == 'cancelled' ) {
// change the recipient of this instance
$wc_emails['WC_Email_Cancelled_Order']->recipient = $customer_email;
// Sending the email from this instance
$wc_emails['WC_Email_Cancelled_Order']->trigger( $order_id );
}
elseif ( $new_status == 'failed' ) {
// change the recipient of this instance
$wc_emails['WC_Email_failed_Order']->recipient = $customer_email;
// Sending the email from this instance
$wc_emails['WC_Email_failed_Order']->trigger( $order_id );
}
}
Код идет в файле function.php вашей активной дочерней темы (или темы), а также в любом файле плагина.
Это должно работать в WooCommerce 3+
Если вам нужно, вместо изменения электронной почты вы можете добавить его существующим получателям:
// Add a recipient in this instance $wc_emails['WC_Email_failed_Order']->recipient .= ',' . $customer_email;
Связанный ответ: отправьте уведомление по электронной почте, когда статус заказа изменится с ожидающего отмены