Variants - Link product options

TyW
Community Manager
Community Manager
428 46 1157

 


Update secondary menus in line with the current selection, to avoid showing unavailable combinations of options when a customer is choosing from multiple menus. In short, you don't want your customers to encounter this:

 

link-01.jpg


When your store's visitors make a selection in the first drop-down, you want the values in the second drop-down right below to be updated to list only those values that are available in combination with their first selection.

 

If a product has three options, you want the same to happen when one selects a value in the second drop-down. You want the values in the third drop-down to be updated to only list values that are available in combination with the two selections made above.

 

This works from top to bottom. Think of the typical "select a country then select a town" scenario. Selecting a country in the first country element updates the second town element to only contain towns found in that country.

 

Shopify does not give you linked options out of the box. It makes all choices in all drop-downs available. For example, all possible sizes will be listed in your Size drop-down and all colors will be listed in your Color drop-down, regardless what combinations exist or are in stock.

 

Linked options can be added to your theme in two steps.

 

  1. From your Shopify admin, go to Online Store > Themes.
  2. Find the theme you want to edit, and then click Actions > Edit code.
  3. Under Snippets, click the link Add a new snippet.
  4. Name your new snippet linked-options.

    link-02.png

  5. In your new snippet file, paste this code hosted on GitHub.
  6. Click Save.
  7. Under Layout, locate the file theme.liquid, and click it to open it in the code editor.
  8. Near the end of the file, right before the closing </body> tag, paste the following code:

    {% render 'linked-options' %}

    link-03.png

  9. Click Save.

TyW | Online Community Manager @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

Replies 59 (59)
VinnyG
Tourist
3 0 1

I am very new to this but i followed the instructions exactly as posted and it is still offering options and showing them as unavailable.  I am using the venture theme if that matters.  Thank you in advance for your assistance.

landl
New Member
4 0 0

Did you ever figure this out?

Seahawksean
Tourist
13 0 0

This tutorial has been rendered moot now that Shopify ONLY offers sectioned themes.  Venture theme being one of them.  But even if you have an older unsectioned one, the author has a note at the top of this page indicating that it won't even work in that. 

Bummer as this has been the closest thing I've found to help me add this exact functionality after Googling for 5 hours. 

LinkedOptions
Shopify Partner
5 0 0

I've just developed an app, King linked options, that will meet your needs, no coding skills are required, we provide a visual configuration interface, and you can get what you want in just three or five minutes.

 

To celebrate the launch of the app, I'm offering 5 free trials on a first-come, first-served basis. Please contact me at getalltool@gmail.com.

JayCDD
Tourist
6 0 6

Has anyone been able to find a workaround with this for Themes where it doesn't work? Im currently using the Warehouse theme from Maestroo and it does not work with square icons or drop down list. Please help lol

circular78
Tourist
11 0 2

@JayCDD wrote:

Has anyone been able to find a workaround with this for Themes where it doesn't work? Im currently using the Warehouse theme from Maestroo and it does not work with square icons or drop down list. Please help lol


Hi ,

 

I am also looking for answers. Using the same Warehouse theme  as @JayCDD . Hopefully , somebody can help.

cristian_c
Tourist
6 0 11

Hey guys,

I am looking for a solution to this problem for Debut theme.

I really believe this should be solved by Shopify already, i have seen many post on this same subject, and it simply makes no sense to display options that are not available.

ndambrosi
Excursionist
14 0 9

I'm searching for this solution for the Debut theme.  Has anyone had any luck or found an app they can recommend to accomplish this? 

Padster
Explorer
49 5 14

Still searching.
How u getting on?

:Paddy

 

ndambrosi
Excursionist
14 0 9

Not yet.   I might check it out and see how it works.

 

For now, I've gone to my translations and I've changed "Unavailable" to "Invalid product combination" as well as labeling the options a little more clearly so the user can understand which sizes in Menu 2 apply to each of the selections from Menu 1.  

samnamiam
New Member
1 0 6

This updated code made it work for debut theme.

https://gist.github.com/jonathanmoore/c0e0e503aa732bf1c05b7a7be4230c61

ndambrosi
Excursionist
14 0 9

Yes, this code is working for me!  Thanks so much!

Padster
Explorer
49 5 14

That one didn't work for me...here's a good video talking u thru it tho for any 1  that wants 2 know - https://www.youtube.com/watch?v=vspWDu_POYA.

Going to try a couple other options today....not sure if it some additional code I can see in my product.liquid ...anyone any ideas?

Any Shopify experts?? ; ) ; ) @TyW 

 

{% comment %}

The contents of the product.liquid template can be found in /sections/product-template/
{% endcomment %}

{% section 'product-template' %}
{% section 'product-recommendations' %}

<script>
window.theme = window.theme || {};
window.theme.strings = window.theme.strings || {};

// Override default values of theme.strings for each template.
// Values are used by JavaScript only; Liquid must be updated separately
window.theme.strings.addToCart = {{ 'products.product.add_to_cart' | t | json }};
window.theme.strings.soldOut = {{ 'products.product.sold_out' | t | json }};
window.theme.strings.unavailable = {{ 'products.product.unavailable' | t | json }};
</script>

 

 

 

Padster
Explorer
49 5 14

Hoooraaaaay!!! I've dun it...[applause]

 

So i followed the youtube above then did wot fella described (im using the narrative theme FYI):

 

"For those of you who are having issues with the default variant not loading and requiring the user to select a variant before the script fires:

This is what worked for me on the Shopify Debut Theme.

Find the following code:
Shopify.linkOptionSelectors({{ product | json }});

It is located in the following if statement

{% if product.available and product.options.size > 1 %}
...
Shopify.linkOptionSelectors({{ product | json }});
...
{% endif %}

Simply move it directly outside of the if statement:

{% if product.available and product.options.size > 1 %}
...
// Line removed from here
...
{% endif %}

// Line added here
Shopify.linkOptionSelectors({{ product | json }});

 

& badabing badaboh! 
SKILLz, cash monies dollar dollar bills coming my way (quickly converted to $btc & $doge ; )

Goodluck : P

ps. shopify community is changing some of the html 4 sum reason so dont copy from here...checkout the comments at https://gist.github.com/jonathanmoore/c0e0e503aa732bf1c05b7a7be4230c61 post Mar 14, 2018

Kishori
Shopify Expert
1 0 0

Thank you, this amazingly worked for me in debut theme.

Hemfarg
New Member
1 0 0

This is awesome, huge thanks

landl
New Member
4 0 0

Have you managed to get that to work? 

JayCDD
Tourist
6 0 6

I ended up biting the bullet and getting this app  - https://apps.shopify.com/variant-swatch-king

Works exactly as intended and very easy to use. Setup didn't integrate completely with theme but Devs were super fast about getting this fixed and working properly.

kachadidit
New Member
1 0 0

Worked for me in debut theme, thank you!

Jezzsterboy
New Member
1 0 0

YES!!!!!! THIS CODE works for me also!!!!! 

Oh, I am using the DEBUT theme.

hank you SO, SOOOOOO MUCH!!!!! 🙂 

Jezz

JonnoW
New Member
1 0 0

Thanks for this, that worked for me on Paralax 5.0 for Shop 2.0.

markboehlen
Shopify Partner
12 0 1

Great to know!

wallyfbaby
New Member
2 0 1

Hi! Did you ever figure this out? I'm also on Debut and having the same problem. It really ruins the user experience when stock is low because they have to click ALL the options just to find a size/colour in stock. Shopify, please fix this 🙂 Thank you!

markboehlen
Shopify Partner
12 0 1

I have updated the script and added a switch for showing sold out.

 

https://gist.github.com/kyleboehlen/fd4ce2f4d24a16b74b1e4a30c914f32d

 

YahyaYavuz
New Member
1 0 0

Hey sir,

 

all of this examples its doesnt works in my theme.

Have you any snippet for this Theme: Prestige OS2.0


Thank you so much. Please help me sir. 🙂

markboehlen
Shopify Partner
12 0 1

I do not have that theme.

 

Does the theme use drop downs for product variants?

billium
Shopify Partner
5 0 1

Has anyone refactored this to work on pills vs dropdowns?  

 

I have been fighting it for a few hours now without success.

 

I thought it would be easy given the existing working code but it is not since each single select(x) is replaced by a group of inputs.

 

markboehlen
Shopify Partner
12 0 1

Hopefully you can get it figured out.

 

I have pushed this issue with Shopify - I believe they need to fix this somehow on the back end.

 

I have looked at the product liquid and haven't yet had the time to see if it could be fixed there.  Even if some of the work could be done there, you would still need some java work.

PascalR
Shopify Partner
37 0 6

Hello, since we have uptaded our theme turbo portland to shopify 2.0 we have a problem. We use langshop to traduce the website in 5 languages. Before, the unavailable combinations were hiding in all languages. Since the update, we added the code procedure and now it is only good for the basic language french. Can you help us

Regards

Pascal

markboehlen
Shopify Partner
12 0 1

Pascal,

My expertise in Java is nearly zero, I had help from others on this.

However I would be willing to try and help or at least point you in the right direction.

 

Mark

PascalR
Shopify Partner
37 0 6
Thanks a lot Mark
markboehlen
Shopify Partner
12 0 1

Pascal,

If it works fine in French but not the other languages, I am guessing that the container ID names (HTML) are changing.  If this is true, then you need to add some logic to get the variable "selectionobject" value to change.  (Line 21)

var selectionobject = '.form__input--select'

PascalR
Shopify Partner
37 0 6
Hello, where i can find the container id names ?
Regards
Pascal
markboehlen
Shopify Partner
12 0 1

I am not familiar with your theme, however in the theme I am using it is in product-form.liquid.  See our comments on line 19:

"Set up some variables that identify the selection, in this theme it is located in product-form.liquid line 98"

bsambell
New Member
1 0 0

Is there a solution for those of us that use Venture theme? Please help!

Padster
Explorer
49 5 14

Hi there,

 

Unfortunately if doesnt seem to be working on the narrative theme...any ideas!? Any help would be greatly appreciated.

& for everybody else reading this post, theres a great guy on utube outlining this issue & how to make the changes https://www.youtube.com/watch?v=vspWDu_POYA.

 

Regards,

:Paddy

@Padster 

 

 

jpeltier78
New Member
1 0 0

Performed exactly as expected. Thank you!

danielagsb
Explorer
78 0 17

Hi! has anyone managed to make it work for the boundless theme? Thank you

Padster
Explorer
49 5 14

https://community.shopify.com/c/Shopify-Design/Linking-product-Options-and-Hiding-Sold-Out-Variants-...

 

may be this will help. Something to do with dropdowsn vs swatches etc...

 

Goodluck 😛

Darren_Murtha
Shopify Partner
4 0 1

I got this to partially work with a 3rd party theme that uses buttons instead of dropdowns.  In the first option, all the buttons change their color to indicate they have been clicked but if I changes to any other value in the first option, the buttons don't light up on the 2nd and 3rd options.   Where should I look? Anyone else encounter this or know what to change?

RobinH
New Member
4 0 0

Got it to work. So that's great, however only for the product pages. Does anyone have an idea how to make it work for products on the homepage?

RobinH
New Member
4 0 0

I got to work for products on the homepage by including

{% render 'linked-options' %}

 

on  home-product.liquid

freedivebird
Tourist
8 0 14

Took me a good few hours to figure out why the code is not working for shops with multiple locale!!

If you are operating a shop front with multiple locales, replace line 92 in linked-options.liquid

  var $addToCartForm = $('form[action="/cart/add"]');

with

  var $addToCartForm = $('form[action$="/cart/add"]');

 And voila!

erialeduab
New Member
1 0 1

I thought I'd post the updated solution on this thread to save everyone some time.

A commentor (Jonathon Moore) on the original GitHub posted a modified code which now works with Shopify's new sectioned themes. It's works perfectly, you just follow the same instructions as the original post. 

Also, according to Coding with Jan, he provides a slightly altered version of the render so it only applies to the Product Pages:

{% if template contains 'product' %}
  {% render 'linked-options' %}
 {% endif %}

 

(H/T to 

NamcoPoolAdmin
New Member
1 0 0

This needs more updoots

eloisegasper
New Member
1 0 0

This works! Thank you so much 

fblome
Excursionist
27 0 9

Still having the issue that I need to select another option to make the script running. Are there any solutions to fix that?

Jowi_Benz
Shopify Partner
3 0 1

I had the same issue, I hired the job with a shopify expert and they fixed it for me. Check them out: Okas Concepts

MHDB
Tourist
3 0 8

Hi @Jowi_Benz 

Are you able to share your solution with the rest of the world?

Would appreciate it a lot!

 

Best,

Marlon

Jowi_Benz
Shopify Partner
3 0 1

Hey @MHDB I don't know the final solution. As I mentioned before, I hired the job with Okas Concepts. I tried it myself following this video: https://youtu.be/vspWDu_POYA and it only worked after selecting 1st and 2nd Options on a Variant and then going back to select the options again, like having to do that in order for the snippet inserted (see video) activates and start working. Apparently for some themes it works right from the get go, but for others you need to tweak a little. The guys at Okas Concepts did it in less than 2 days. Probably is nothing complicated but you gotta have some good coding knowledge and understanding of Themes structures.

Wish you luck! 

PublicApps
Shopify Partner
146 5 35

The solution differs for different themes/stores. Also, when themes get updated, the solution may get outdated, because it makes assumptions about the store's code. Anyone with a little web dev experience, would be able to help you with this though.

Public Apps | Theme customization & App development
 - Was my reply useful? Like it to let me know!
 - Did I answer your question? Please mark as Accepted Solution.
 - Need more help? Contact us.

AvidBrio
Shopify Expert
294 17 27

@PublicApps   this solution work with many themes we implemented  may be all other help 

@MHDB  @Seahawksean 
https://community.shopify.com/c/Technical-Q-A/how-to-show-the-linked-option-on-Minimal-theme/m-p/103...

If you find our comment helpful, hit the like button and accept it as a solution.
Want us to implement custom changes in your store? Contact us
Email me directly - jim@avidbrio.com
Jowi_Benz
Shopify Partner
3 0 1

Hi there,

Is there now any available solution for sectioned themes? 

Thanks,

LiamR
New Member
1 0 1

Hi there, I can get this to work on my product pages. But if I use a "featured product" block on another page, it doesn't work.

I've tried adding the {% render 'linked-options' %} tag into the includ-featured-product.liquid snippet but still doesn't seem to be working. Not sure if I'm pasting it in the wrong section or if it just flat out won't work for this type of use.

MHDB
Tourist
3 0 8

I have the same problem with my Narrative Theme. The code works fine on the product page, but not in the featured product section. Although these two sections get the dropdown fields from the same file "product-unit-price.liquid".

Unfortunately, I could not find out what is different with product-template.liquid.

I hope this topic is still relevant and there is a solution.

@TyW  Are you able to provide us with further information?

Best,
MHDB

CherryChung
Excursionist
23 0 7

Thanks, it worked perfect for Modular theme.

piranha
New Member
7 0 0

When having 2 dropdown menus for 2 variant options, I go ahead and change one option and then it says "unavailable" even though that variant-combination exists. Then I go ahead and change the variant option and it goes to "available". Then I switch back to the old variant options which showed "unavailable" which now shows as "available".

markboehlen
Shopify Partner
12 0 1

I am not exactly sure what would cause that.  Thinking on how the drops are populated, I would look at the order of your Variants and make sure the first ones are available - meaning the first ones that the system picks on initial load.