An Example of Shopify’s Add to Cart API Code using Javascript

If you’re utilizing a (.js) file, accessing the cart object directly through Shopify’s REST API isn’t possible. However, opting for a (.js.liquid) file type will provide access to the cart object.


Solution:

If there is a lack of diversity in the product, this method can be applied.


product.selected_or_first_available_variant.id

When utilizing the AJAX cart API of Shopify.

Frequently Asked Questions