Add Custom Note to WooCommerce Order Confirmation Email

How to add custom note to woocommerce order confirmation email; Add custom message to order confirmation email woocommerce; Woocommerce order confirmation email custom note; Customize woocommerce order confirmation email with notes; How to include custom text in woocommerce order email; Add personalized note to woocommerce order email; Woocommerce email customization add custom note; How to edit woocommerce order confirmation email to add note; Add custom order note in woocommerce email; Woocommerce order email add custom message;

Explanation

Want to add a personal touch to your WooCommerce order confirmation emails? This snippet lets you include a custom note in the emails sent to your customers when their order is being processed.

  • Where it goes: This code hooks into the part of WooCommerce that handles email order details.
  • What it does: It checks if the email being sent is the "customer processing order" email. If it is, it adds a custom message to the email.
  • Customizing the message: You can change the text in the $custom_note variable to whatever message you want to send to your customers.
  • Plain text vs. HTML: The code handles both plain text and HTML emails, ensuring your message looks good no matter what format your customer receives.

Simply adjust the message to fit your brand's voice, and your customers will receive a warm, personalized note with their order confirmation. Easy peasy!

Code

<?php
// Add a custom note to WooCommerce order confirmation email

// Hook into WooCommerce email order details
add_action('woocommerce_email_order_details', 'wp_dudecom_add_custom_note_to_email', 10, 4);

/**
 * Add a custom note to the WooCommerce order confirmation email.
 *
 * @param WC_Order $order The order object.
 * @param bool $sent_to_admin If the email is being sent to the admin.
 * @param bool $plain_text If the email is in plain text.
 * @param WC_Email $email The email object.
 */
function wp_dudecom_add_custom_note_to_email($order, $sent_to_admin, $plain_text, $email) {
    // Check if the email is the customer processing order email
    if ('customer_processing_order' === $email->id) {
        // Define your custom note
        $custom_note = __('Thank you for your order! We appreciate your business and hope you enjoy your purchase.', 'text-domain');

        // Output the custom note
        if ($plain_text) {
            echo "\n" . $custom_note . "\n"; // For plain text emails
        } else {
            echo '<p>' . esc_html($custom_note) . '</p>'; // For HTML emails
        }
    }
}
?>

Instructions

To add a custom note to the WooCommerce order confirmation email, follow these steps:

File Location: Add the code to your theme's functions.php file or a custom plugin file.

Prerequisites:

  • Ensure WooCommerce is installed and activated on your WordPress site.

Implementation Steps:

  1. Access your WordPress dashboard.
  2. Navigate to Appearance > Theme Editor if you are adding the code to functions.php. Alternatively, use a code editor if you are adding it to a custom plugin file.
  3. Locate and open the functions.php file of your active theme or your custom plugin file.
  4. Copy and paste the provided code snippet into the file.
  5. Customize the message by editing the text within the $custom_note variable to fit your brand's voice.
  6. Save the changes to the file.
  7. Test the functionality by placing a test order to ensure the custom note appears in the order confirmation email.

Need help with implementation or want more advanced functionality? Visit wp-dude.com for expert WordPress assistance.