My Add to Cart Button is not working, gets stuck on Adding

A few weeks back the button was working just fine. I cant add products to the cart from the product page I only can add products to the cart using the fast add to cart. I havent made any changes to my theme’s code. Theme is Foodie.

When I change the theme it works just fine.

https://andesblossom.ca/collections/50-stem-bulk-rose-collection/products/50-cobalt-blue-roses?variant=49082422624574

This comes out in the log when you click the add to cart.

In your theme you have a function

function id(id) {
    if (typeof id !== 'number' || isNaN(id)) {
      throw new TypeError('Theme Cart: Variant ID must be a number');
    }
  }

In case the variant Id is not a number, it will throw an error. By any chance you’ve changed variant ids to values that are not numbers?

I think the issue conflict is with the subscription app because atc works fine on the collection page with a plus button.
I suggest ask from the subscription app support alternatively you have to debug the issue manually or ask a developer to check it.

No I haven’t. Even when you click on a product you can see the variant id on the url.

I also checked the subscription app by disabling it. But it still happening.

The product page form id refers to a string

product-buttons-form-template--21902126481726__main

which can’t be converted to a number.

Whereas on fast add it refers to an input field which holds the numeric value of the variant:

input#formVariantId

Makes sense! Do you have any idea why is that function taking my id as a string?

The original theme uses that hidden input field as the id of the form. I suppose that is a dynamic assignment after the page paints to the browser. Since the original id of the form is a string. Then something repaints the form and it goes back to the string. I will try to have a look at it, and see the change history of the id attribute of that form.

I see it’s now working correctly. May I ask you what the issue was?

Hi Michal, so basically it was a theme bug so I had to contact them for them to solve it. This was the message they sent me before fixing it:

It’s not working because you didn’t have your variants block enabled. Since it doesn’t appear you have any variants anyway, I’ve enabled that block, it does not change the look of your shop at all, and now items can be added to the cart. We’re investigating that issue generally in the theme now.

I see, thanks for clarifying. I’m glad they’ve fixed it quickly!