Products without variants not being added to cart

1 0 0

Hey guys,


I am having an issue with a clients site, where if a product does not have a color variant it will not be added to the cart.

I know that that is the issue as I have tested it. But the developer is not currently available to make a change to the code.


Here is the js.liquid:

  let selectedVariantColor;
  let selectedVariantId;
  function addToCart(){
    let quantityN = Number($('.dn_quantity').val());
    selectedVariantColor = $('.tt-options-swatch').find(' a').attr('data-value');
    $('div#secret_variants div').each(function(){
      let dataId = $(this).attr('data-id');
      let dataTitle = $(this).attr('data-title');
      if(dataTitle == selectedVariantColor){
        selectedVariantId = dataId
    console.log('variant and quantity', selectedVariantId,quantityN);
    $.post('/cart/add.js', {
        {id: selectedVariantId,
         quantity: quantityN
    //     window.location.href='/cart';
  // add to cart handler
  $('.addToCartBtn').on('click',()=> addToCart())
I appreciate any and all help 🙂
Replies 2 (2)

Shopify Partner
525 55 102


Replace this code :- 

      if(dataTitle == selectedVariantColor){
        selectedVariantId = dataId
With this code:- 
  selectedVariantId = dataId.
So, basically just remove the if condition
Ittanta Technologies Pvt. Ltd. | Shopify Expert
If reply is helpful, please Like and Accept Solution.
To hire us, contact us at

2860 684 735

Hi @Carlos138,

Please send your site and if your site is password protected, please send me the password. or you can send me the theme name.

I will check it for you.

LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool.
Effortlessly sell on biggest marketplaces like Amazon, Etsy, eBay, Facebook etc with bulk listing tool, real-time sync & smart order management. Use LitCommerce free for 1-year now!