Add customer name to woocommerce email-header.php heading

enter image description here

I want to update the header saying "custommer_name sent a GIFT for you".It's not working !!

<table border="0" cellpadding="0" cellspacing="0" width="600" id="template_header">
                <tr>
                    <td id="header_wrapper">
                        <h1><?php
                              $order = new WC_Order($order_id);
                              echo $order->get_billing_email() . $email_heading; 
                     ?></h1>
                    </td>
                </tr>
</table>

Answers 1

  • For this you need to override class or create your custom email type, I can give a short hint on the modifications to be made in the class further you can override in your child theme or plugin if you don't want to loose the changes on woocommerce update.

    In /woocommerce/includes/emails/class-wc-email-customer-completed-order.php

    On line 37:

    $this->placeholders   = array(
        '{site_title}'   => $this->get_blogname(),
        '{order_date}'   => '',
        '{order_number}' => '',
        '{order_name}' => '',
    );
    

    Here I added {order_name},

    Then on line 86

    if ( is_a( $order, 'WC_Order' ) ) {
        $this->object                         = $order;
        $this->recipient                      = $this->object->get_billing_email();
        $this->placeholders['{order_date}']   = wc_format_datetime( $this->object->get_date_created() );
        $this->placeholders['{order_number}'] = $this->object->get_order_number();
        $this->placeholders['{order_name}'] = $this->object->get_billing_first_name();
    }
    

    Here I defined First name to {order_name}, now you can use this placeholder in woocommerce email settings at /wp-admin/admin.php?page=wc-settings&tab=email&section=wc_email_customer_processing_order


Related Questions