If you require more than 100 variants for a product, and the additional product options don’t require changes to the total product price, then follow the steps below. This method uses Metafields and Line Item Properties to present customers with additional product options.
The example provided here uses a newly installed copy of the Dawn theme. The details of the implementation will vary depending on your theme and any customizations that have already been made.
Note:
This customization is for Online Store 2.0 themes, and doesn’t apply to vintage Shopify themes. Find out your theme’s architecture version.
Considerations before adding additional product options
Before you begin making the customizations outlined in these instructions, consider the following limitations and risks.
- Inventory cannot be tracked for product options that are added using this method. This can lead to overselling or fulfillment issues.
- Product options that are created using this method cannot make changes to the total product price.
- If you use a third-party fulfillment service, then you’ll need to ensure that your workflows are compatible with these changes.
Before you begin
To complete this procedure, you’ll need the following:
- Knowledge of HTML, CSS and Liquid code, and Online store 2.0.
- To change a theme, you must have the Themes permission.
- To change a product, you must have the Products permission.
- Familiarity with Metafields and Line Item Properties.
It’s best practice to duplicate your theme to create a backup copy. This makes it easy to discard your changes and start again if you need to.
Display product options that are stored as metafields on your online store
Complete this procedure to update your product and cart pages to display product options that are stored as metafields.
Step 1: Update the product template to display the product options block1. In your Shopify admin, go to Online Store >Themes.
-
For the theme you want to customize, click Actions then Edit code.
-
In the Sections folder, click on the main-product.liquid file.
-
In the
main-product.liquid
file, find the{%- case block.type -%}
switch statement and add the following code as a new block statement:{% when "custom_product_option" %} {% if block.settings.values != blank %} {% assign line_item_property_enable = true %} {% if block.settings.title != blank %} {% assign custom_product_option_title = block.settings.title %} {% endif %} {% assign custom_product_options = block.settings.values | strip_html | split: "," %} {% endif %}
-
In the main-product.liquid file, find the
{%- form 'product' -%}
tag inside thebuy_buttons
When statement, and add the following code:{% if line_item_property_enable %} {% endif %}
-
In the main-product.liquid file, find the
{% schema %}
code at the bottom of the file and add the following code:{ "type": "custom_product_option", "name": "t:sections.main-product.blocks.custom_product_option.name", "limit": 1, "settings": [ { "type": "text", "id": "title", "label": "t:sections.main-product.blocks.custom_product_option.settings.title.label" }, { "type": "richtext", "id": "values", "label": "t:sections.main-product.blocks.custom_product_option.settings.values.label" } ] },
-
Save your changes.
Step 2: Add theme settings to the product options block1. In your Shopify admin, go to Online Store >Themes.
-
For the theme you want to customize, click Actions then Edit code.
-
In the Locales folder, click on the en.default.schema.json file.
-
In the en.default.schema.json file, find the
main-product
section code and add the following code as a new block:"custom_product_option": { "name": "fCustom product option", "settings": { "title": { "label": "ffTitle" }, "values": { "label": "ffOption values" } } },
-
Save your changes.
Step 3: Update the cart pop-up notification to display product options1. In your Shopify admin, go to Online Store > Themes.
-
For the theme you want to customize, click Actions then Edit code.
-
In the Sections folder, click on the cart pop-up file, for example, cart-notification-product.liquid.
-
In the cart-notification-product.liquid file, find the Liquid code looping through
item.options_with_values
and add the following code after the closing{% endfor %}
tag:{%- for property in item.properties -%} {%- assign property_first_char = property.first | slice: 0 -%} {%- if property.last != blank and property_first_char != '_' -%} <dt>{{ property.first }}: </dt> <dd> {%- if property.last contains '/uploads/' -%} {{ property.last | split: '/' | last }} {%- else -%} {{ property.last }} {%- endif -%} </dd> {%- endif -%} {%- endfor -%}
-
Save your changes.
Adding additional options to a product using metafields
Complete this procedure to create a new metafield, and then add the metafield to a product that you want to have more than 100 variants.
Step 1: Create a new product option type as a metafield1. From your Shopify admin, go to Settings > Metafields.
- Click Products.
- Click Add definition.
- Enter a name for the metafield. For example, Shoelaces.
- In the Namespace and key field, change
my_fields
toproduct_option
. For example, changemy_fields.shoe_laces
toproduct_options.shoe_laces
. - Enter a description for the metafield. For example, Shoelace colors.
- Click Select content type, and then click Text.
- Click on Multi-line text.
- Optional: Add Validation rules to your metafield.
- Click Save.
Step 2: Add the product option type to a product and add product options1. From your Shopify admin, go to Products.
- Click on the product that you want to add the product option type to, for example Wool shoes.
- In the Metafields section, click on the product option that you want to add. For example, Shoelaces.
- Add as many product options as you want. Each option must be separated by a comma. For example Black, White, Brown, Grey.
- Click Save.
Add the product options block to your product page1. In your Shopify admin, go to Online Store > Themes.
- For the theme you want to customize, click Customize.
- Click on the drop-down menu at the top of the page and click on Products, then Default product.
- In the Product information section, click Add block.
- Click on Custom product option. The Custom product option block will appear in the Blocks section.
- In the Product information section, click on the Custom product option block to customize it.
- Enter a title for the product option block. For example, Shoelaces.
- For the Option values, click Insert dynamic source.
- Select the metafield that you want to use for the Product options. For example Shoelace colors. Click Insert.
- The Custom product options block will appear in the theme preview.
- To adjust the location of the Custom product option block, navigate to the Default product page and drag the Custom product option block to the desired location.
- Save your changes
Next Steps- Preview a product that you’ve added additional product options to on your store.
- Customer notifications may need to be edited to include the new product option details.