Always get variant= at the end of every product page URL

pete96
New Member
3 0 0

Hi -

 

Would anybody know how we can make sure we always get the variant= and then the product id number at the end of all our product page URLs?

 

Even for product pages that don't actually have any varaitions?

 

Theme is Minimal

 

Many thanks!

0 Likes

@pete96 

There are many ways to do it, but it will require some coding knowledge.

1. All products URL have a JSON endpoint with all complete data. For instance, take this product:

https://partakefoods.com/products/crunchy-cookie-variety-pack

And add .json at the end, and you'll receive all of its data:

https://partakefoods.com/products/crunchy-cookie-variety-pack.json

From there you just need to create a Javascript function to get the current variant.

2. Perhaps the simpler one, in your product-template file ensure that the product has only one variant and create a data attribute with something like "data-custom-variant-id" passing the variant ID. From there you'll just need to add it via Javascript. 

If you're unfamiliar with coding feel free to reach out just by clicking here, I'll be happy to help.

Kind regards,
Diego

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Using a free theme? Improve it with copy/paste code snippets clicking here.
◦ Looking to hire an experienced developer? Same day response: ezfycode@gmail.com.
0 Likes
pete96
New Member
3 0 0

Hi Diego,

You are a genius!!!

Many thanks for idea #1 and for pointing this out.  I am sure we can do something with this, and it won't require us to make any changes to the site at all, everything we need will be in the data returned by the json call.

I know where to come for any development we might need! (and it might be soon!)

Hope all is well down there in sunny Portugal,

 

Many thanks for taking the trouble to reply and for giving me this info

 

pete

 

 

0 Likes