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
/**
 * Send new order email to customer.
 *
 * @param int $order_id The ID of the newly created order.
 * @return void
 */
function wpturbo_send_new_order_email( $order_id ) {
    // Get the order object
    $order = wc_get_order( $order_id );

    // Check if the order exists and is valid
    if ( ! $order ) {
        return;
    }

    // Get the customer's email address
    $customer_email = $order->get_billing_email();

    // Set the email subject
    $subject = __( 'New Order Confirmation', 'wpturbo' );

    // Set the email headers
    $headers = array(
        'Content-Type: text/html; charset=UTF-8',
    );

    // Get the email template
    $email_template = wpturbo_get_email_template(); // Replace with your own email template function

    // Set the email message
    $message = $email_template; // Replace with your own email template HTML

    // Send the email
    wp_mail( $customer_email, $subject, $message, $headers );
}
				

In this updated code, the @param tag has been added to document the $order_id parameter of the wpturbo_send_new_order_email function. It specifies that the parameter should be an integer representing the ID of the newly created order.

Additionally, a @return tag has been added to indicate that the function does not return any value (void).

Documentation is important as it helps other developers understand the purpose and usage of the code. It provides clarity and makes the code more maintainable. By adding documentation to your code, you make it easier for yourself and others to work with and enhance the code in the future.

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