user1615837
user1615837

Reputation: 89

Shopify Cart API - Add Product To Cart without Variant

I am using the code below to add a product variant to the cart. However, it doesn't work if the product doesn't have any variants.

How can I add a product without variants to the cart? I tried using the Product ID, but that doesn't work.

Any assistance would be greatly appreciated.

jQuery.post('/cart/add.js', {
  items: [
  {
    quantity: 1,
    id: 39486502174869,
    properties: {
      'Length': metres_required
    }
  }]
});

Upvotes: 1

Views: 1357

Answers (1)

Onkar
Onkar

Reputation: 2584

When you have no variation in the product, you can use it this way.

product.selected_or_first_available_variant.id

while using the Shopify AJAX cart API.

Upvotes: 1

Related Questions