Liquid/JS to select different default variant (3-Pack) on product page load?

Liquid/JS to select different default variant (3-Pack) on product page load?

guisemen
Excursionist
44 2 5

Hi there,

 

I'm hoping to implement code to change the default variant selection on page load for this product page in the Dawn theme:

https://guisemen.com/products/green-stick?variant=47615513460969

 

Let me know how you would recommend going about this... you're guidance is GREATLY appreciated!

 

Best,

Will

-Will
Replies 6 (6)

Shadab_dev
Shopify Partner
1524 81 168

This is a good one man. Will definitely try this out. Which product do you need to be selected on load the 3 pack or 6 pack?

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
guisemen
Excursionist
44 2 5

Hi there!  Thanks so much. Hoping to have the page default to the 3 pack on initial page load!

-Will
guisemen
Excursionist
44 2 5

Hey Shadab, no stress if you haven't been able to, but I was curious whether you've had any success?

-Will
Shadab_dev
Shopify Partner
1524 81 168

Hi @guisemen I did try man. But I guess it will take a bit more of looking up. I was able to load item of my choice but then selecting another didn't change anything. 

 

But honestly this is a good one and I am up for it. Sorry to not update you and thank you for ringing a bell kind of a motivator.

 

Will update this time as it goes 

 

Thanks

Shadab 

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.
guisemen
Excursionist
44 2 5

No stress -- if this would take a substantial amount of work let me know and we can figure out a rate via email.

-Will
Shadab_dev
Shopify Partner
1524 81 168

Hi will,

 

I kind of got a solution for it, not the best one I will say that it does have a gotcha but it does fulfill the purpose of the project which is to select a variant of our choice by default. 

 

Let me explain how this works. So when you first enter the product page or when the page loads for which we need this feature what happens is Shopify's code is running and selecting the first available variant but I am refreshing the page again to change the variant to our selection. So the page kind of loads two times which might not be a big issue if your site speed is good and loads faster. So this happens on every load and by every load I mean every time user comes back to this specific product page the page loads twice with our choice of variant selected. Rest of the functionality works pretty fine like if user wants to select other variant and adding to cart, etc.

 

Just want to let you know how this is working before you throw a deal.

 

Please reach out via mail for a convenient conversation. 

 

Thanks 

Shadab Ali 

Buy me Coffee, if you feel i was helpful. Email Me here or WhatsApp me with this link for any help with shopify theme customizations or any project in web dev. If this is helpful, please Like and Accept the solution.