Documentation
Feedback
Guides
VTEX IO Apps

VTEX IO Apps
Basic components
Add To Cart Button
The add-to-cart button is responsible for adding products in the Minicart.

The add-to-cart-button block is responsible for adding products in the Minicart (minicart.v2).

{"base64":"  ","img":{"width":2094,"height":1052,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":407330,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-add-to-cart-button-0.png"}}

The Add To Cart Button only works in stores using the Minicart v2. In this scenario, it successfully works in the Shelf component as well as in the Product Details page. If you are using the Minicart v1, configure the Buy Button block in the Product Details page and the Product Summary Buy Button in the Shelf component instead.

Configuration

  1. Import the vtex.add-to-cart-button app to your theme's dependencies in the manifest.json, for example:
"dependencies": { "vtex.add-to-cart-button": "0.x" }
  1. Add the add-to-cart-button to other theme block using the product context, such as the product-summary.shelf. In the example below, the add-to-cart-button is added to the flex-layout.row block from the store.product template (which uses the product context):
"store.product": { "children": [ "flex-layout.row#product", ] }, "flex-layout.row#product": { "children": [ "add-to-cart-button" ] }
Prop nameTypeDescriptionDefault value
onClickBehaviorenumControls what happens when users click on the button. Possible values are: go-to-product-page, add-to-cart, and ensure-sku-selection (if multiple SKUs are available, users will be redirected to the product page to select the desired one. If the product only has 1 SKU available, it will be added to the cart once the button is clicked on).add-to-cart
onClickEventPropagationenumControls whether the 'onClick' event (triggered upon user clicks) should be spread to the page's parent elements. Possible values are: disabled and enabled.disabled
isOneClickBuybooleanWhether the user should be redirected to the checkout page (true) or not (false) when the Add To Cart Button is clicked on.false
customOneClickBuyLinkstringDefines the link to where users will be redirected when the Add To Cart Button is clicked on and the isOneClickBuy prop is set to true./checkout/#/cart
customToastUrlstringDefines the link to where users will be redirected when the Toast (pop-up notification displayed when adding an item to the minicart) is clicked on./checkout/#/cart
textstringDefines a custom text message to be displayed on the Add To Cart Button.Add to cart (automatic translation will be applied according to your store's default language)
unavailableTextstringDefines a custom text message to be displayed on the Add To Cart Button when a product is unavailable.Unavailable (automatic translation will be applied according to your store's default language)
customPixelEventIdstringDefine the id for the event that will be sent by the the button upon user interaction.undefined

Customization

In order to apply CSS customizations in this and other blocks, follow the instructions given in the recipe on Using CSS Handles for store customization.

CSS Handles
buttonText
buttonDataContainer
tooltipLabelText
Contributors
3
Photo of the contributor
Photo of the contributor
Photo of the contributor
+ 3 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Basic components
Autocomplete
Contributors
3
Photo of the contributor
Photo of the contributor
Photo of the contributor
+ 3 contributors
On this page