Generate a new order email to send to customer when they have created an order

WPTurbo » Snippets » Generate a new order email to send to customer when they have created an order
0

Created with:

Visibility: 

public

Creator: Johan Lindberg

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php
/**
 * Get the email template for the new order confirmation email.
 *
 * @return string The email template HTML.
 */
function wpturbo_get_email_template() {
    // Retrieve necessary order data
    $order_id = get_the_ID();
    $order = wc_get_order( $order_id );
    $order_number = $order->get_order_number();
    $order_total = $order->get_total();
    $order_date = $order->get_date_created()->format( 'F j, Y' );

    // Construct the email template HTML
    $email_template = "
        <html>
        <head>
            <title>New Order Confirmation</title>
        </head>
        <body>
            <h1>New Order Confirmation</h1>
            <p>Thank you for your order. Here are the details:</p>
            <ul>
                <li>Order Number: $order_number</li>
                <li>Order Total: $order_total</li>
                <li>Order Date: $order_date</li>
            </ul>
            <p>If you have any questions, please feel free to contact us.</p>
        </body>
        </html>
    ";

    return $email_template;
}
				

In this code, we have a wpturbo_get_email_template function that retrieves the necessary order data, such as the order ID, order number, order total, and order date. Then, we construct the email template HTML using these variables.

The email template includes a heading, a thank you message, and a list of order details. You can customize the HTML structure and content of the template to match your needs.

Remember to replace the placeholder functions (get_the_ID(), wc_get_order(), etc.) with the appropriate functions for retrieving the order data in your specific context.

Please make sure to customize the email template according to your requirements and styling preferences.

Register an account to save your snippets or go Pro to get more features.