selectCallback in Shopify.SelectOptions is always returning `null`

Viewed 287

selectCallback sets variant equal to null on all my option selections besides the initial call. On the initial call, it logs the variant with the first color and size.

const productJson = JSON.parse($(`#${id}`).attr('data-product'));

new Shopify.OptionSelectors(id, {
    product: productJson,
    onVariantSelected: selectCallback,
});

const selectCallback = (variant, select, options) => {
    console.log(variant) // `null`
}

I'm expecting to get variant object which matches my size/color selections.

1 Answers

before you call callback your method should be defind


  element.addEventListener('blur', callback, { once: true });

    function callback() {
      element.classList.remove(focusClass);
      element.removeAttribute('tabindex');
    }
Related