Created
May 27, 2024 13:14
-
-
Save danielcharrua/2f6a71b485751d38d74781ab3d4d12d3 to your computer and use it in GitHub Desktop.
send woocommerce additional email when local pickup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('woocommerce_order_status_processing', 'send_custom_email_for_local_pickup', 10, 1); | |
function send_custom_email_for_local_pickup($order_id) { | |
if (!$order_id) return; | |
// Obtener el pedido | |
$order = wc_get_order($order_id); | |
// Comprobar si el método de envío es 'local_pickup' | |
$shipping_methods = $order->get_shipping_methods(); | |
foreach ($shipping_methods as $shipping_method) { | |
if ($shipping_method->get_method_id() == 'local_pickup') { | |
// Obtener datos del pedido | |
$order_date = wc_format_datetime($order->get_date_created()); | |
$order_total = $order->get_formatted_order_total(); | |
$billing_email = $order->get_billing_email(); | |
// Contenido del correo | |
$email_heading = 'Nuevo pedido para recogida local'; | |
$email_body = '<p>Hola,</p>'; | |
$email_body .= '<p>Has recibido un nuevo pedido para recogida local.</p>'; | |
$email_body .= '<p>Detalles del pedido:</p>'; | |
$email_body .= '<ul>'; | |
$email_body .= '<li><strong>Número de pedido:</strong> ' . $order->get_order_number() . '</li>'; | |
$email_body .= '<li><strong>Fecha del pedido:</strong> ' . $order_date . '</li>'; | |
$email_body .= '<li><strong>Total del pedido:</strong> ' . $order_total . '</li>'; | |
$email_body .= '<li><strong>Correo del cliente:</strong> ' . $billing_email . '</li>'; | |
$email_body .= '</ul>'; | |
$email_body .= '<p>Puedes ver más detalles del pedido <a href="' . admin_url('post.php?post=' . $order_id . '&action=edit') . '">aquí</a>.</p>'; | |
// Usar la plantilla de correo de WooCommerce | |
$mailer = WC()->mailer(); | |
$message = $mailer->wrap_message($email_heading, $email_body); | |
// Obtener los encabezados del correo electrónico de WooCommerce | |
$headers = array('Content-Type: text/html; charset=UTF-8'); | |
// Enviar el correo | |
$mailer->send('[email protected]', $email_heading, $message, $headers); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment