LogoLogo
Build appsContact API support
Storefronts
  • Build apps
  • Site Templates
  • API Reference
  • Changelog
Storefronts
  • Ecwid storefronts overview
  • Get started
    • Storefront customization options
    • Quickstart: customize storefront with Ecwid JS API
  • Track Storefront events
    • "Page is loaded" events
    • "Customer logged in" event
    • "Cart details are changed" event
    • "New order is placed" event
    • "Instant Site section load" events
  • Get Storefront details
    • Get Ecwid store ID
    • Get storefront language and currency
    • Get visitor location
    • Get public app details
  • Manage customers on the storefront
    • Get logged in customer's details
    • Manage customer's cookie consent
    • Log out customer
  • Open page on the storefront
    • Overview of open page options
    • Open product pages with params
    • Open category pages with params
    • Open search page with params
    • Open account pages with params
  • Manage cart and checkout
    • Get cart details
    • Add product to the cart
    • Remove product from the cart
    • Fully clear the cart
    • Create pre-filled shopping carts
    • Calculate cart details
    • Send customer to the checkout
    • Set customer's email for the checkout
    • Set customer's comments for order
    • Set customer's shipping and billing addresses
    • Set custom order referer
  • Store configuration settings
    • Overview
    • Behavioral configs
    • Design configs

Lightspeed® 2025

On this page

Was this helpful?

  1. Manage cart and checkout

Add product to the cart

Ecwid.Cart.addProduct()

This method allows you to add a new product position to the shopping cart. It accepts two arguments: product and callback. The product argument accepts either product ID or a product object with extended details including product ID, quantity, selected options, or subscription product settings.

When you use this method, it first checks the product by specified ID for stock and variations. If the selected options match one of the variations, Ecwid will check its stock first. If you don't have enough stock to add a product, Ecwid adds the available quantity. If the product is out of stock, nothing is added to the shopping cart.

Code example:

var product = {
  id: 10,
  quantity: 3,
  options: {
    "Size": "L"
  },
  recurringChargeSettings: { 
    recurringInterval: "month",
    recurringIntervalCount: 1,
    },
  callback: function(success, product, cart) {
    // ...  
  }
}

Ecwid.Cart.addProduct(product);

product argument fields

Field
Type
Description

id

number

Internal product ID.

quantity

number

Quantity of the product that will be added to the cart.

options

object options

Map of the selected product options (option name as a key and option value as a value).

selectedPrice

string

Selected price for the product with the parameter "nameYourPriceEnabled": true. If specified for a product with "nameYourPriceEnabled": false, the product will be added with the default price.

recurringChargeSettings

string

Defines subscription product settings if needed.

callback

string

Defines the callback function.

Code example for options object:

"options": {  
    "Size": "M",  
    "Print_number": "9"  
}

recurringChargeSettings

Field
Type
Description

recurringInterval

string

Charge recurring interval. Supported values: DAY, WEEK, MONTH, YEAR.

recurringIntervalCount

number

Charge recurring interval. Supported values: for DAY - 1 (daily), for WEEK - 1 (weekly), 2 (biweekly), for MONTH - 1 (monthly), 3 (quarterly), for YEAR - 1 (annually).

callback

Callback function receives 4 arguments: success, product, cart, error

Name
Type
Description

success

boolean

Indicates operation status. If true - the product was added to the shopping cart.

product

product object after the operation.

cart

object cart

cart object after the operation.

error

string

If success is false, contains error message.

Last updated 2 months ago

Was this helpful?

object

product