How to add an engraving option to a Shopify product
If you are selling the products that can be engraved, you’ll need to have an engraving option on your product page. This will be a field where the customer can enter the text that they want engraved and which will get attached to the order you receive.
In this article we’ll look at very clear and simple steps to add an engraving option to your product page.
It will take you only a few minutes to get your engraving product up and running.
You can edit your theme’s code by creating an alternate product page template that includes custom form fields, or line item properties. You can then apply your new template to any product for which you want to collect customization information from customers.
Step 1: Create a template that includes line item properties
To create a new product page template:
- From your Shopify admin, go to Online Store > Themes.
- Find the theme you want to edit, and then click Actions > Edit code.
- In the Templates directory, click Add a new template.
- Choose
product
from the drop-down menu, and name the templatecustomizable
: - Click Create template. This creates a copy of your
product.liquid
template calledproduct.customizable.liquid
. The new file will open in the code editor. - Find the following line of code:1{% section 'product-template' %}
Replace it with1{% section 'product-customizable-template' %} - Click Save.
- In the Sections directory, click Add a new section.
- Name your new section file
product-customizable-template
. Click Create section. Your new file will open in the code editor. - Delete all of the default code so that the file is empty. Copy all of the content from your
product-template.liquid
file (in the Sections directory), and paste it into your newproduct-customizable-template
file. - Click Save.
Step 2: Create custom form fields
You can add as many custom form fields to your product page as you need. You can use the Shopify UI Elements Generator tool to easily generate the HTML and Liquid code for each form field that you want to add to your cart page. This tool was created by Shopify to help simplify the process of adding custom user interface elements, such as form fields and icons, to Shopify themes.
- Go to the Shopify UI Elements Generator.
- In the Set your form field section, select the type of form element that you want to use from the Type of form field drop-down menu:
- If you want your theme to prevent customers from adding a product to the cart before they have filled in your form field, check Required.
- You can see a preview of your form field in the Preview section:
- Copy the generated code from the box in the Grab your code section:
Step 3: Add custom form fields
To add custom form fields to your template:
- From your Shopify admin, go to Online Store > Themes.
- Find the theme you want to edit, and then click Actions > Edit code.
- In the Sections directory, click
product-customizable-template.liquid
. - Find the code
type="submit"
in the file. This is part of the code for the Add to cart button. On a new line above the block of code that contains the Add to cart button, paste the form fields for your product customization:
In the above example, the form field code adds anEngraving
field where customers can enter text for a custom engraving. The line where you place the code determines where the form field will appear on your product page. You can experiment with putting the code in different places in the file. - Click Save.
To make the new form fields appear on product pages, you need to set your customizable products to use the new product-customizable-template.liquid
template that you created.
Step 4: Apply your new template to a product
To apply a template to a product:
- From your Shopify admin, go to Products > All products.
- Click the name of the product that will use your new template.
- In the Theme templates section, choose
product.customizable
from the Product template menu. - Click Save.
The custom form fields that you created will now appear on that product’s page. Repeat the steps to enable the template on multiple products. You can use the bulk editor to enable your template on many products at once.
Step 5: Show customizations in the cart
If your theme doesn’t display customizations in the cart, then you can add some code to either your cart-template.liquid
, or your cart.liquid
file to check for line item properties and display them if they exist.
Show line item properties in the cart
To show product customization information in the cart:
- From your Shopify admin, go to Online Store > Themes.
- Find the theme you want to edit, and then click Actions > Edit code.
- In the Sections directory, click
cart-template.liquid
. If your theme doesn’t have acart-template.liquid
, then open the Templates directory and clickcart.liquid
. - Find the line containing the code
{{ item.product.title }}
. On a new line below, paste the following code:123456789101112131415{% assign property_size = item.properties | size %}{% if property_size > 0 %}{% for p in item.properties %}{% assign first_character_in_key = p.first | truncate: 1, '' %}{% unless p.last == blank or first_character_in_key == '_' %}{{ p.first }}:{% if p.last contains '/uploads/' %}<a class="lightbox" href="{{ p.last }}">{{ p.last | split: '/' | last }}</a>{% else %}{{ p.last }}{% endif %}<br>{% endunless %}{% endfor %}{% endif %} - Click Save.
Update links that remove items from the cart
Any links that remove items from your cart will need to be updated to work with custom line item properties:
- From your Shopify admin, go to Online Store > Themes.
- Find the theme you want to edit, and then click Actions > Edit code.
- In the Sections directory, click
cart-template.liquid
. If your theme doesn’t have acart-template.liquid
, then open the Templates directory and clickcart.liquid
. - Find any a tag that has an href value starting with
/cart/change
. - Change the full href value to
href="/cart/change?line={{ forloop.index }}&quantity=0"
. - Repeat these steps for every a tag in cart-template.liquid that has an href value starting with
/cart/change
. - Click Save.
Update item quantity fields in the cart
Any fields that display item quantities in your cart will also need to be updated to work with custom line item properties:
- From your Shopify admin, go to Online Store > Themes.
- Find the theme you want to edit, and then click Actions > Edit code.
- In the Sections directory, click
cart-template.liquid
. If your theme doesn’t have acart-template.liquid
, then open the Templates directory and clickcart.liquid
. - Find any input tag that has an name value of
updates[{{ item.id }}]
. - Change the full name value to
name="updates[]"
. - Repeat these steps for any input tag in
cart-template.liquid
that has an name value ofupdates[]
. - Click Save.
Step 6: Show customizations in email templates
You can optionally also display line item properties in email notifications. This will let customers see their product customizations when they receive an email about their order.
- From your Shopify admin, go to Settings > Notifications.
- Click the name of the notification template that you want to add line item properties to.
- Find the following code:1{{ line.title }}
Replace it with:1{{ line.title }}{% for p in line.properties %}{% unless p.last == blank %} - {{ p.first }}: {{ p.last }}{% endunless %}{% endfor %} - Click Save.
Repeat these steps for any other email notifications that you want to include line item properties.
Source: Shopify
Thank you so much for this amazing post! I could not have done personalization on Shopify without this post! It saved me! And it was so thorough and easy to understand. Great job! Thank you again.
Really good post, thank you. However, the “required” field in the UI Elements Generator does not seem to work. Customers can still proceed to checkout with a blank field, even when “required” is checked ad custom text field creation. Anyone have the same issue and found a solution?
Thanks so much for this! So helpful! Is it possible to add a second engraving option without it being attached to the first (and showing up on every product the first is on)? I have tried several things, would love some help on that!