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:
$(document).ready(function(){
let selectedVariantColor;
let selectedVariantId;
function addToCart(){
let quantityN = Number($(‘.dn_quantity’).val());
selectedVariantColor = $(‘.tt-options-swatch’).find(‘li.active 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’, {
items:[
{id: selectedVariantId,
quantity: quantityN
}
]
}).always(function(data){
window.location.href=‘/cart’;
})
// window.location.href=‘/cart’;
}
// add to cart handler
$(‘.addToCartBtn’).on(‘click’,()=> addToCart())
})
I appreciate any and all help ![]()