How to use metafield for product variant redirect in Dawn theme?

Solved

How to use metafield for product variant redirect in Dawn theme?

Gumf
Shopify Partner
26 1 3

So I have a product will 10 variants but I have also had to create separate listings for each variant (clients request) so that on a collection page you can view all variations. However, is there a way to redirect the variation product listing to the main product listing which contains the variants?

 

I have created a global url metafield called Redirecturl but can't figure out how to implement it. I tried adding the following code to the theme.liquid file but it didn't work:

 

 

    {%- if product[handle].metafields.global.Redirecturl -%}
    <script>
         window.location = "{{ product[handle].metafields.global.Redirecturl }}";
     </script>
{%- endif -%}

 

 

 

I am using the theme - Dawn.

Accepted Solution (1)
omarhussain
Shopify Partner
32 5 7

This is an accepted solution.

 

you don't need to add handle 
product already contains hadnle


 {%- if product.metafields.global.Redirecturl -%}
    <script>
         window.location = "{{ product.metafields.global.Redirecturl }}";
     </script>
{%- endif -%}

 

View solution in original post

Replies 4 (4)
Gumf
Shopify Partner
26 1 3

That would be great if you could. Thanks

Gumf
Shopify Partner
26 1 3

I would prefer to discuss it here so others can benefit from the solution. Thanks

omarhussain
Shopify Partner
32 5 7

This is an accepted solution.

 

you don't need to add handle 
product already contains hadnle


 {%- if product.metafields.global.Redirecturl -%}
    <script>
         window.location = "{{ product.metafields.global.Redirecturl }}";
     </script>
{%- endif -%}

 

Gumf
Shopify Partner
26 1 3

This was spot on thank you! I just needed to tweak the .global to .custom too.

 

Thank you so much!