skip to Main Content

I’m looking for a way to send all WordPress emails using a custom WooCommerce template so all emails will look the same.

The path to the template would be:

woocommerce/emails/my-custom-woocommerce-template.php

4

Answers


  1. Does it have to all be templatized in a single file? If not, a combination of these entry points can probably get you the standardization you’re looking for:

    1. email-header.php lets you customize the start of the email including the header image (if you need to do more than change its URL). It opens the layout tags for the rest of the email content
    2. email-footer.php lets you customize the footer, and closes the layout tags started in the header.
    3. email-styles.php or the woocommerce_email_styles filter let you customize the CSS (see some gotchas in my article here).
    4. Various actions/filters are scattered throughout the emails for customizing individual parts.
    Login or Signup to reply.
  2. You can use the below function. It is working

    function myplugin_woocommerce_locate_template( $template, $template_name, $template_path ) {
        global $woocommerce;
    
        // List of all templates that should be replaced with custom template
        $woo_templates = array( 
            'emails/admin-new-order.php',
            'emails/admin-failed-order.php',
            'emails/admin-cancelled-order.php',
            'emails/customer-completed-order.php',
            'emails/customer-new-account.php',
            'emails/customer-note.php',
            'emails/customer-on-hold-order.php',
            'emails/customer-processing-order.php',
            'emails/customer-refunded-order.php',
            'emails/customer-reset-password.php',
        );
        //Check whether template is in replacable template array
    
        if( in_array( $template_name, $woo_templates ) ){
    
            // Set your custom template path
            $template = your_template_path.'emails/my-custom-woocommerce-template';
        }
    
        // Return what we found
        return $template;
    }
    add_filter( 'woocommerce_locate_template', 'myplugin_woocommerce_locate_template', 10, 3 );
    
    Login or Signup to reply.
  3. add_filter( 'wp_mail', 'your_wp_mail_action' ); //  $args = compact( 'to', 'subject', 'message', 'headers', 'attachments' )
    function your_wp_mail_action( $args ) {
        global $your_prefix_your_email_args; // the args you could use in my-custom-woocommerce-template file
    
        $your_prefix_your_email_args = $args;
    
        ob_clean();
        get_template_part( 'woocommerce/emails/my-custom-woocommerce-template' );
    
        $args['message'] = ob_get_clean();
    
        // ... your logic
    
        return $args;
    }
    
    Login or Signup to reply.
  4. To view and update email settings, log into your website dashboard. In the left-hand menu, click on WooCommerce → Settings.

    There, you’ll find several options tabs at the top. Click Emails to view the following templates

    you can custom all as you want

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search