Отправка письма клиенту по отмененному заказу в WooCommerce | #NeonaFM

Отправка письма клиенту по отмененному заказу в WooCommerce

Отправка письма клиенту по отмененному заказу в WooCommerce

По умолчанию, woocommerce отправляет письмо об отмене и неудавшемся заказе только администратору сайта. Что же делать, если вы хотите, чтоб клиент тоже получал письмо об этом?

Этот код решит вашу проблему, добавить его надо в фал function.php вашей активной дочерней темы или в саму тему:

add_action('woocommerce_order_status_changed', 'send_custom_email_notifications', 10, 4 );
function send_custom_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 );
}
}

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Меню