4

I'm trying to insert custom variable(company, Phone Number) into my customer email template. But it's not working for me.

 {{template config_path="design/email/header_template"}}

    <p class="greeting">{{trans "%name," name=$customer.name}}</p>
    <p>{{trans "Welcome to %store_name." store_name=$store.getFrontendName()}}</p>
    <p>
        {{trans
            'To sign in to our site, use these credentials during checkout or on the <a href="%customer_url">My Account</a> page:'

            customer_url=$this.getUrl($store,'customer/account/',[_nosid:1])
        |raw}}
    </p>
    <table class="email-credentials">
        <tr>
            <th>{{trans "Email:"}}</th>
            <td>{{var customer.email}}</td>
        </tr>
        <tr>
            <th>{{trans "Password:"}}</th>
            <td><em>{{trans "Password you set when creating account"}}</em></td>
        </tr>
    </table>
    <p>
        {{trans
            'Forgot your account password? Click <a href="%reset_url">here</a> to reset it.'

            reset_url="$this.getUrl($store,'customer/account/createPassword/',[_query:[id:$customer.id,token:$customer.rp_token],_nosid:1])"
        |raw}}
    </p>
    <br />
    <p>
    {{var company}}
    </p>
    <br/>
    <p>{{trans "When you sign in to your account, you will be able to:"}}</p>
    <table class="email-features">
        <tr>
            <td>
                <table>
                    <tr>
                        <td>
                            <img src="{{view url='Magento_Customer/images/icn_checkout.png'}}" height="30" width="30" alt="{{trans 'Quick Checkout'}}" />
                        </td>
                        <td>
                            <h3>{{trans "Proceed through checkout faster"}}</h3>
                        </td>
                    </tr>
                </table>
            </td>
            <td>
                <table>
                    <tr>
                        <td>
                            <img src="{{view url='Magento_Customer/images/icn_status.png'}}" height="30" width="30" alt="{{trans 'Order Status'}}" />
                        </td>
                        <td>
                            <h3>{{trans "Check the status of orders"}}</h3>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <table>
                    <tr>
                        <td>
                            <img src="{{view url='Magento_Customer/images/icn_address.png'}}" height="30" width="30" alt="{{trans 'Manage Addresses'}}" />
                        </td>
                        <td>
                            <h3>{{trans "Store alternative addresses"}}</h3>
                            <p>{{trans "For shipping to multiple family members and friends"}}</p>
                        </td>
                    </tr>
                </table>
            </td>
            <td>
                <table>
                    <tr>
                        <td>
                            <img src="{{view url='Magento_Customer/images/icn_history.png'}}" height="30" width="30" alt="{{trans 'Order History'}}" />
                        </td>
                        <td>
                            <h3>{{trans "View past orders"}}</h3>
                        </td>
                    </tr>
                </table>
            </td>
    </table>
    <br/><br/>

{{template config_path="design/email/footer_template"}}

Any help on this?

5
  • 1
    please share something you tried.
    – P S
    Commented Jan 9, 2018 at 16:19
  • I tried to inserted {{var company}}. but no luck Commented Jan 9, 2018 at 16:24
  • @Anime see my thread updated Commented Jan 9, 2018 at 16:29
  • is that company yours or customer's?
    – P S
    Commented Jan 9, 2018 at 16:43
  • @Anime customers company. Commented Jan 9, 2018 at 16:45

1 Answer 1

1

Try with:

{{var customer.company}} and {{var customer.phone_number}}

If it's not working, then the customer object for email templates doesn't contain the newly added customer data (company and phone number).

You can check the function newAccount() in \vendor\magento\module-customer\Model\EmailNotification.php which contains $customerEmailData that holds all customer related data for the email template.

You could create a plugin or override to add your custom data to it.

1
  • Customer address is there in the object but still not showing even I used above ref of your answer and customer.getAddresses(). Commented Jan 10, 2018 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.