Customize emails based on shipping method
Guide to display different content in your emails depending on the shipping method - e.g. shipping vs. pickup.
In Shoporama you have different templates for your transactional emails. Sometimes it makes sense to customize the email text based on the shipping method the customer has chosen - for example, if the customer has chosen "in-store pickup" instead of delivery.
Why customize emails by shipping method?
Imagine a customer has selected "Pickup in store" as their shipping method. When you mark the order as shipped, the customer receives an email saying "Your order is now shipped". But that doesn't make sense - the customer has to pick up the order themselves.
By customizing the email, you can instead write "Your order is ready for pickup" for customers who have chosen pickup and keep the normal text for other shipping methods.
1. Find the shipping method ID
First, find the ID of the shipping method you want to target. Do the following:
- Go to Settings (gear) → Shipping tab.
- Click Edit next to the shipping option you want to work with
- Look at the URL in the browser - it ends with a number, e.g.
/shipping/edit/7664 - Make a note of this number - it is the shipping method ID
2. Customize the email template
Now you need to edit the relevant email template. For the "order sent" email, this is the order_sent.html file in your theme.
Insert an if statement that checks the shipping method ID:
<{if $order}> <{$shipping = $order->getShipping()}> <{if $shipping->getShippingId() == 7664}> <p>Your order is ready for pickup!</p> <p>Stop by the store during our business hours.</p> <{else}> <p>Your order has been shipped! </p> <p>You will receive a tracking email shortly.</p> <{/if}> <{/if}
Important.
Remember to change 7664 to the ID you found in step 1. You can add multiple elseif blocks if you have multiple shipping methods with different texts.
3. Available variables in email templates
In mail templates, you have access to the order and all its data. Here are the most useful ones:
| Variable | Variable Description |
|---|---|
$order | The order object |
$order->getShipping() | The shipping method on the order |
$shipping->getShippingId() | The ID of the shipping method |
$shipping->getName() | The shipping method name (e.g. "PostNord") |
$order->getTrackingId() | The track & trace number |
4. Examples of advanced customization
You can also use the shipping method name instead of the ID if you prefer:
<{$shipping = $order->getShipping()}> <{if $shipping->getName()|str:'pickup'}> <p>Your order is ready for pickup</p> <{elseif $shipping->getName()|str:'parcel shop'}> <p>Your order has been sent to your chosen parcel shop</p> <{elseif $shipping->getName()}></p> <{/if}>
Tip.
You can customize all email templates this way - not just order_sent.html. For example, you can also customize the order receipt(order_receipt.html) with delivery information based on the shipping method.
How to edit the email templates
The email templates are located in your theme's templates/emails/folder. You can edit them via:
- Theme editor - directly in Shoporama admin under Themes
- SFTP - download and edit in your preferred program (requires Pro subscription)
Need help customizing your emails? Contact us at support@shoporama.dk.