Home > database >  Edit header and footer only for "customer-on-hold-order" email notifications in WooCommerc
Edit header and footer only for "customer-on-hold-order" email notifications in WooCommerc

Time:10-26

I tried to edit the header and footer of emails of my store, but I'm only able to edit if it goes directly to the template of ALL emails.

I also tried to copy the email-header.php and email-footer.php to my child theme and nothing happens.

Since that the template customer-on-holder-order have listed the code

/*
 * @hooked WC_Emails::email_header() Output the email header
 */
do_action( 'woocommerce_email_header', $email_heading, $email ); ?>

...

/*
 * @hooked WC_Emails::email_footer() Output the email footer
 */
do_action( 'woocommerce_email_footer', $email );

How can I find/edit this? Any advice?

CodePudding user response:

It is correct that the woocommerce_email_header and the woocommerce_email_footer action hook occur in multiple template files.

However, to target a specific email you can use $email->id, since $email is passed to both hooks as an argument

So you get:

// Header
function action_woocommerce_email_header( $email_heading, $email ) {    
    // Target
    if ( $email->id == 'customer_on_hold_order' ) {  
        echo 'customer on hold order header';
    }
} 
add_action( 'woocommerce_email_header', 'action_woocommerce_email_header', 10, 2 );

// Footer
function action_woocommerce_email_footer( $email ) {
    // Target
    if ( $email->id == 'customer_on_hold_order' ) {  
        echo 'customer on hold order footer';
    }   
}
add_action( 'woocommerce_email_footer', 'action_woocommerce_email_footer', 10, 1 );

Code goes in functions.php file of the active child theme (or active theme). Tested and works in Wordpress 5.8.1 & WooCommerce 5.8.0

  • Related