Skip to main content

Product Purchase

This family builds product add-to-cart UI. The parent is AddToCartForm; the usual children are AttributeSelector, AddToCartButton, and BuyNowButton.

Components

Component keyRole
OmeWooAddToCartFormOwns the product ID, product type, variation ID, stock/availability flags, and submitted form state.
OmeWooAttributeSelectorSelects one variation attribute object from omewoo.attributes.
OmeWooAddToCartButtonAdds a product by itself in standalone mode, or submits the parent form in form-submit mode.
OmeWooBuyNowButtonUses the parent form payload, adds the item, then redirects to checkout.

Authoring Structure

AddToCartForm
AttributeSelector loop over product attributes
AddToCartButton with trigger=form_submit
BuyNowButton

Use AddToCartButton as a standalone button only when it is outside an AddToCartForm.

Quick Start

Variable product purchase form
<OmeWooAddToCartForm product='{{"product_id":"{this.id}","product_type":"{this.omewoo.product.type}"}}'>
{#slot default}
{#loop this.omewoo.attributes as attribute}
<OmeWooAttributeSelector target='{{"attribute":{attribute}}}' />
{/loop}
<OmeWooAddToCartButton behavior='{{"mode":"counter","trigger":"form_submit"}}' />
<OmeWooBuyNowButton content='{{"label":"Buy now"}}' />
{/slot}
</OmeWooAddToCartForm>

AddToCartForm Props

PropMeaning
product.product_idProduct ID. Use {item.id} in product loops and {this.id} on single product templates.
product.product_typeProduct type, such as simple or variable. Use omewoo.product.type from product dynamic data.
product.variation_idOptional fixed variation ID. Usually empty when selectors provide variation state.
availability.unavailableDisables the form when authored or dynamic product availability says the product cannot be bought.
availability.availablePositive availability flag from dynamic data.
availability.stock_statusStock status used by form sync and disabled state.

Runtime blocks submit if the product is unavailable or if a required variable product option has not been selected.

AddToCartButton Props

PropMeaning
behavior.modefixed renders a normal button; counter renders quantity input plus button.
behavior.triggerstandalone sends its own Store API add request; form_submit submits the parent purchase form.
behavior.product_idRequired for standalone buttons. Ignored by form-submit buttons.
quantity.default, min, max, stepQuantity input defaults and bounds. Runtime clamps invalid values.
content.labelButton text.
content.successMsgTemporary text after a successful add.
accessibility.aria_labelButton accessible label.
accessibility.input_aria_labelQuantity input accessible label in counter mode.

E2E verifies standalone quick add updates CartCount, while a standalone-trigger button inside AddToCartForm does not accidentally submit the form.

AttributeSelector Props

PropMeaning
target.attributeA full attribute object from omewoo.attributes. It contains key, label, required flag, and options.
behavior.select_first_optionSelects the first available option when nothing is selected.
ui.modeselect, radio, or button-radio.
ui.aria_labelAccessible selector name.
ui.default_labelSelect trigger label before selection.

Each option carries value, label, variation ID, availability, and stock status. Unavailable options are marked disabled and cannot be selected.

BuyNowButton Props

PropMeaning
content.labelButton text.
accessibility.aria_labelOptional accessible label.
checkout.urlAuthored redirect target. If empty, runtime uses the localized Woo checkout URL.

BuyNowButton must be inside an AddToCartForm because it serializes the form payload before redirecting.

Scenario Coverage

ScenarioCovered behavior
cart_count_add_to_cartStandalone add updates count and success state.
add_to_cart_button_inside_formStandalone add button inside a form is skipped by runtime.
product_archive_simple_addProduct loop card form submits and updates cart count.
product_single_simple_addQuantity input clamps to max and submitted quantity updates cart count.
variable_product_requires_variationVariable product blocks submit until a variation option is selected.
variation_selector_button_radioButton-radio selector selects available option and rejects unavailable option.
buy_now_redirectBuy-now adds to cart then redirects to checkout.
out_of_stock_product_disabledOut-of-stock form state disables the purchase button.