3

Wondering if there is any way to assign variants to custom radio inputs? I'd like to set up tiered shipping with different rates for 2 Day, 3 Day and Standard shipping. I can do this with variants but the drop down won't work for me.I'd like to have date information and a datepicker in order to choose preferred shipping dates and have it all appear on a modal with the rest of the delivery options. Line item properties won't work because as far as I know they cannot affect price. So I wondered, if I created different variants for the different shipping rates, could I direct them to my own radio buttons? I've attached a screenshot of what I've got so far. The 3 radio buttons on the right are what I'd like to use rather than the built in Shopify drop down. Thanks in advance for your help.

enter image description here

susan
  • 372
  • 2
  • 5
  • 19

3 Answers3

4

I would suggest checking out this discussion on the Shopify wiki: Mixing dropdown and radio buttons on product page

Caroline posted this answer:

That's a difficult one, because you need to use option_selection.js to 'descramble' variants into options, and option_selection.js generates drop-downs, one for each option. Personally, I would keep that.

You can add radio buttons for your colors — while keeping your Color drop-down on the page and hide it with CSS — then update the selected option in the drop-down when a radio button is checked.

In the following example, anchor elements are used instead of radio buttons, but the method is the same: http://wiki.shopify.com/Color_swatches_made_easy_in_Shopify

The lastest version of that color swatch tutorial is available on the Shopify Wiki here, and I've used it before with success (although only with the default code, not radio buttons).

If that doesn't work for you, I think you're looking at a much more complicated thing to implement... See these other discussions about using radio buttons for variants I found on the Shopify wiki:

EDIT:

In comments below:

...still unsure if I can assign the buttons to custom variant titles using javascript elements.

I had a play around with this idea, and I'm not sure if this is exactly what you are after, but it might give you some ideas on where to start.

My variants are:

  • Standard Shipping
  • 3 Day Express Shipping. Additional $15
  • 2 Day Express Shipping. Additional $25

I added a span below the variants in product.liquid where I display the estimated delivery date, and some jQuery that updates the estimated delivery date text in the span depending on the shipping date selected in the datepicker.

Shopify variants as radio buttons

I used the code from Caroline Schnapp in this discussion to create radio buttons for the variants (the same as you did). I modified the code slightly by adding a Line Item Property in a hidden input field just before the end of the form:

<input type="hidden" id="delivery-date" name="properties[DeliveryDate]" /> 

And added 2 lines to the end of this jQuery function to update the hidden line item property when a radio button is clicked:

jQuery("input[type='radio']").click(function() {
  var variant_price = jQuery(this).attr("data-price");
  jQuery(".price-field span").html(variant_price);
  var variant_compare_at_price = jQuery(this).attr("data-compare-at-price") || '';
  jQuery(".price-field del").html(variant_compare_at_price);

  var delivery_date = jQuery("ul li input[type='radio']:checked").siblings("span").html();
  jQuery("#delivery-date").val(delivery_date);
});

Then when the user clicks the Purchase button to add the item to their cart, it shows the variant and line item property something like this:

Shopify cart with line item properties

Not sure if that's exactly what you're after, but hopefully some of it is helpful!

EDIT 2:

Here's the gist: https://gist.github.com/stephsharp/6865599

Steph Sharp
  • 11,462
  • 5
  • 44
  • 81
  • Steph-thank you so much for this. The links are all very helpful, appreciate you pointing me in the right direction. I played around with some of it this morning and I'm thinking it might now work how I'd like. The variants can definitely be displayed in radio button format, however, I don't think they'll be able to point to my custom titles with javascript dates. I'll work a bit more on it and let you know. Do you have any direct experience with this that might be applicable? – susan Sep 30 '13 at 15:35
  • @susan I'm afraid I haven't implemented radio buttons for variants before, but if you get stuck feel free to post the code you have so far and I'm happy to take a look at it. – Steph Sharp Oct 01 '13 at 09:51
  • Well, I certainly appreciate your help and your offer is very generous. Thank you. I'm going to work on this and if you like I'll keep you posted, let you know how it turns out. – susan Oct 01 '13 at 14:17
  • Steph, it seems as if you have particular expertise with Shopify so wanted to keep you updated on anything I learned. Not sure if comments are the right way to do this...? Anyway, I tried the code provided by Caroline Schnapp at one of the links you gave: http://ecommerce.shopify.com/c/ecommerce-design/t/change-to-radio-buttons-50294. Works beautifully for converting the variants dropdown to radio buttons. However still unsure if I can assign the buttons to custom variant titles using javascript elements. I'll keep you posted my findings. – susan Oct 03 '13 at 14:29
  • @susan Glad you've got the radio buttons working. I made an edit to my answer with an idea for how to handle custom titles using a hidden line item property. – Steph Sharp Oct 06 '13 at 11:23
  • This is totally amazing! WOW, I am super impressed! I can't believe you pulled this off. I've been working on it and haven't been able to make it happen. THANK YOU!! I'm trying to implement right now but having issues, I think just with my html for some reason. I think my brain is just scrambled from this. Would you mind posting your html, especially interested in seeing your custom spans mentioned above. Thank you so much again!! You're amazing! – susan Oct 06 '13 at 19:08
  • I have gotten this to work! Almost...can't seem to get those dates to populate...probably my jquery and html combined. If you don't mind sharing the code for your spans or have any suggestions I'd certainly appreciate it. Thanks again, I'm really happy about this! – susan Oct 07 '13 at 02:05
  • Sure, I'll put my code in a gist and post the link after I finish work :) – Steph Sharp Oct 07 '13 at 02:11
  • @susan I've included a link to the gist at the end of my answer. It's not perfect - you'll want to find a better way to set ids for the spans below each variant (I used the variant price which I wouldn't recommend, it was just a quick way to set up the example). – Steph Sharp Oct 07 '13 at 11:38
  • Very, very, very cool Steph!! Can't believe this is finally going to happen, thank you so much!! – susan Oct 07 '13 at 13:20
  • I was sick the last couple days but wanted to check in since you did all this super fantastic work. I did give it a whirl and, while I was able to get the radio buttons displaying propertly as before with Caroline Schnapp's code for that but having issues getting the dates to display. I'm going to keep at it but thinking if I don't have it by tomorrow maybe you wouldn't mind checking out my work? Let me know and thank you soooo much again! Really cool. – susan Oct 08 '13 at 18:31
  • Sure, no problems. Let me know how you go! – Steph Sharp Oct 08 '13 at 23:06
  • So, just finally getting over a horrible awful flu and just finished working on this (again). Got it! Still having a bit of problems getting the dates to line up properly but whoo hoo! Just can't thank you enough for this!! Really really appreciate it. Thank you very very very much!! Cheers, Susan – susan Oct 12 '13 at 12:59
  • Yay! I'm really glad you got it working. It was my pleasure :) – Steph Sharp Oct 13 '13 at 07:56
  • Just had to thank you again! Really happy to have this feature implemented...finally! – susan Oct 17 '13 at 23:41
  • You're welcome, I had fun working though it with you! – Steph Sharp Oct 19 '13 at 05:13
  • Hi Steph! Hope you get this message...Just realized the dates we have displayed are for the Express Shipping options are for 2 or 3 days respectively, not considering holidays or weekends. Eek. I have my datepicker set up with holidays or weekends and a minDate...would it be possible to do the same with these? Sorry, I'm very very new to web dev. Appreciate so much much your help! – susan Oct 26 '13 at 13:33
  • Hi Susan, I'm sure that could be done. The shipping options I used were just for demonstration purposes, and you should be able to set up your datepicker however want. Have you tried copying your datepicker code into my sample code? Perhaps you could post what you have so far. – Steph Sharp Oct 30 '13 at 02:54
  • Hi Steph, You're wonderful to respond to such an old post. Thank you. I posted a git with my datepicker code here: https://github.com/zipotontic/SampleCode-uiDatepicker/tree/master The git also includes the script I'm using to format the dates. I guess my confusion is that the code is so long and I will need three: one for the date generated by the datepicker with a minDate 4, one with a minDate of 2 and one with a minDate of 3, all excluding holidays & weekends. Then, in addition, the script to the date. Just a lot of code to do 3 separate times...hoping I could condense it somehow into one. – Zipotontic Oct 30 '13 at 13:12
  • Hi Susan, sorry I haven't gotten back to you until now. I've been flat out these last few weeks. Do you still need help with this? It may be quicker for you to contact a Shopify Expert (http://experts.shopify.com/) and get them to help you out. – Steph Sharp Nov 19 '13 at 03:26
  • Hi Steph, figured it out, thanks. Really appreciate you getting back to me, thanks so much for all of your help! Just adjusted my script a bit and was able to get the dates to display no problem. Cheers, Susan – susan Nov 29 '13 at 21:46
2

Also note that there is no reason to use option_selector.js code. Shopify hands off all the product information including the options and variants as JSON. You are free to build any data structure you want, assign any events you want and generally go about client-side coding as you need to go. Without using that bit of code. It is merely a suggestion about how one can do things with Shopify. It gets widespread use, but it is not the end all, be all.

David Lazar
  • 10,865
  • 3
  • 25
  • 38
  • Thank you very much for your post David. I was glad to read it as I've seen a couple comments in Shopify Wiki stating it should not be changed unless absolutely necessary. This gives me confidence that what I'm interested in doing might be possible. – susan Sep 30 '13 at 20:28
1

We recently added the ability to get variant options and values in Liquid so you're not forced to render radio or select elements with JS. Check out the updated docs at https://help.shopify.com/themes/liquid/objects/product#product-options_with_values

Carson
  • 4,541
  • 9
  • 39
  • 45