As the title says, I am trying to create a conditional metaobject menu that only shows when certain product variant is selected. This menu has a few options and when the buyer adds product to cart, the information should appear in the cart and checkout processes.
What I had done so far:
1. Created a metaobject definition:
Field Type Example value Purpose
| trigger_option | List (single-line text) | All White | The variant option value that should reveal this dropdown (e.g. the value of Size / Color etc.). |
|---|---|---|---|
| label | Single-line text | Cord Length | Text that shows above the dropdown and in the cart. |
| value | List (single-line text) | [“1m”,“2m”,“3m”,“4m”] | The items that will become s. |
2. Created a product metafield with a metaobject type that references the definition above. The namespace and key is: custom.dropdowns and it allows for a list of entries (multiple metaobject references).
3. Added the following code into a liquid code block inside my product information section, in between the variant picker and the buy buttons:
{%- if product.metafields.custom.dropdowns != blank -%}
{%- assign idx = 0 -%}
{%- for dd in product.metafields.custom.dropdowns.value -%}
{%- assign cleaned = dd.trigger_option | remove: "[" | remove: "]" | remove: '"' | split: "," -%}
{%- for trigger in cleaned -%}
{%- assign idx = idx | plus: 1 -%}
{%- endfor -%}
{%- endfor -%}
{%- endif -%}
4. Added the following Javascript into another liquid code block right under the previous one:
For some reason this is not working and no drop-down menu is displayed when the variant options are selected. Can someone tell me what I’m doing wrong and how to fix this?
By the way I am using Atelier theme, one of the new Horizon themes and the page I am trying to add it to is this one: https://www.orientalbazarstudio.com/products/flexible-bamboo-pendant-light?
Thanks in advance!