Docs
Free ON WEBFLOW.IO DOMAINS

Add to Cart

Method
Utility
Adds variants to the cart programmatically.

Shopify Storefront data and cart logic is bound to your Webflow elements through Shopyflow attributes. Connecting your Webflow site to Shopify is done by adding custom attributes to your Webflow elements.

Yet, you are not required to type or edit attributes manually. Shopyflow provides you with the pre-configured components needed to create your store, as copyable Webflow elements right in Webflow designer.

All the copyable Shopyflow Components are native editable Webflow elements. There is no layout or styling limitation on any element.

In the below image hover your mouse on the hotspots to see all the required Shopyflow attributes to build a product page like this in Webflow

Webflow designer
Custom Attributes
sf-add-to-cart="1"
Custom Attributes
sf-change-quantity="1"
Custom Attributes
sf-change-option="{Option Name}"
Custom Attributes
sf-cart-count="1"
Custom Attributes
sf-change-option="{Option Name}"
Custom Attributes
sf-product="{Product ID}"
Custom Attributes
sf-show-image="1"
Attribute Name
window.Shopyflow.addToCart()
Attribute Value
True or 1
Nesting Rule
Can be placed anywhere in the site
Methods
>
Add to Cart
Method
window.Shopyflow.addToCart()
<script>

  /**
   * @param {Object[]}   lineItems - An array of items to add to the Shopify cart
   * @param {boolean} useShopifyId - Determines whether to to use simple ID or a full Shopify ID
   * @param {boolean}   getNewCart - Indicates whether to add the line items to a new empty cart
   *
   */

  // With simple variant/merchandise ID

  const lineItems = [{
      merchandiseId: '50184857682223',
      // quantity: 1        Optional. Defaults to 1 if not defined.
      // attributes: [],    Optional. Attributes to add to lineItem as {key: value}[]
      // sellingPlanId: '', Optional. Selling plan ID of the variant for subscription.
  }];

  window.Shopyflow.addToCart({ lineItems });


  // With Shopify's variant/merchandise ID

  const lineItemsShopifyId = [
      {
          merchandiseId: 'gid://shopify/ProductVariant/50184857682223',
          quantity: 5
      },
      {
          merchandiseId: 'gid://shopify/ProductVariant/87186257667291',
          quantity: 3
      }
  ];

  window.Shopyflow.addToCart({
      lineItems: lineItemsShopifyId,
      useShopifyId: true
  });

</script>
Class name
window.Shopyflow.addToCart()
Target elements
Can be placed anywhere in the site
Methods

Webflow app usage

Webflow app settings

Inner components

Module contents

Available methods

No items found.

Method

contents

No items found.

State management

No items found.

Related Utilities

No items found.
Can't find a solution? Join our Discord server to get an instant reply from our experts and the community.