WooCommerce module

Add to Cart block

An add-to-cart button with quantity and price, for any product or the product being viewed.

Overview

The Add to Cart block puts a working WooCommerce add-to-cart button anywhere — a landing page, a comparison table, a blog post. Choose a product, or leave it empty to use the product being viewed (in single product templates or product loops). Simple products get a quantity field and AJAX add to cart; products that need choices (variable, grouped, external) get WooCommerce’s “Select options” / “Buy” link instead.

At a glance

Block name
wpbb/add-to-cart
Module
WooCommerce
Find it by searching
Add to Cart
Requires
WooCommerce installed and active
Works with
WooCommerce must be installed and active. The WooCommerce module only appears when it is.
Loads JavaScript on the site
WooCommerce’s own add-to-cart script, for simple products

When and why to use it

  • Product landing pages.
  • Buy buttons in blog reviews.
  • Custom single-product templates.

Example scenarios

  • Landing page: product “Starter kit”, price on, full-width button “Get the kit”.

How to add the Add to Cart block

  1. Open the editor. In your WordPress dashboard go to Pages (or Posts) and click the page you want to edit, or click Add New. For headers, footers and templates, use Appearance → Editor (block themes).
  2. Add a new block. Click the blue + (Block Inserter) button in the top-left corner, or the small + that appears where you want the block. You can also type / on an empty line.
  3. Search for the block. Type Add to Cart in the search field. Brigade Blocks appear in the Brigade Blocks category and show the coral block icon.
  4. Insert it. Click Add to Cart in the results. The block appears with a product picker.
  5. Configure the content. Edit the text directly on the block, then open the Settings tab (gear icon) in the right-hand sidebar for the options described below. If the sidebar is hidden, click the gear icon in the top-right corner.
  6. Customise the design. Switch to the Styles tab (half-filled circle icon) to change colours, spacing, borders and more — see Design & styling.
  7. Save or publish. Click Save draft to keep working later, Preview to check it, or Publish / Update to make it live.

Content settings

You set up this block in two places: on the block itself in the editor, and in the Settings tab (gear icon) of the sidebar on the right. Every option is listed below, with its default value.

Settings panel: Product

Product

What it does
The product the button adds.
What to enter or choose
Search and pick one product, or leave empty.
Default
The current product
How to use it
Start typing a product name and pick it from the suggestions.
When to use it
On normal pages. Leave empty in product templates.
Example
“Starter kit”.
Result
Empty = the current product (single product page or loop item).

Quantity field

What it does
Shows a quantity input before the button.
What to enter or choose
On or off.
Default
On
How to use it
Click the switch to turn it on (blue) or off.
When to use it
For products bought in multiples.
Example
Off for one-off items.
Result
Hidden automatically for products “sold individually” and for non-simple products.

Price

What it does
Shows the price above the button.
What to enter or choose
On or off.
Default
Off
How to use it
Click the switch to turn it on (blue) or off.
When to use it
When the price is not shown nearby.
Example
On.
Result
WooCommerce’s price (with sale price).

Full-width button

What it does
Stretches the button.
What to enter or choose
On or off.
Default
Off
How to use it
Click the switch to turn it on (blue) or off.
When to use it
Optional.
Example
On in narrow columns.
Result
The button fills its row.

Button text

What it does
Custom button label for simple products.
What to enter or choose
Text, or empty for WooCommerce’s “Add to cart”.
Default
Empty
How to use it
Type into the text field. Changes appear in the preview right away.
When to use it
Optional.
Example
“Get the kit”.
Result
The button shows your text.

Design & styling

Select the block, open the Styles tab in the settings sidebar (the half-filled circle icon next to the gear) and use the three pickers at the top of the Style panel:

  1. Element — which part of the block to style.
  2. State — Normal, or a state such as Hover (only the states the part supports are offered).
  3. Device — Desktop, Tablet or Mobile, for values that can differ per screen size.

Only panels that make sense for the chosen part and state are shown. The full meaning of every control is in the Styling Controls guide; below is exactly what Add to Cart offers.

Element: Button selected first

The button. Hover and Focus.

Styles-tab controls for “Button”
PanelControlPer deviceAvailable in states
TypographyFont family—Normal
Font sizeYesNormal
Weight—Normal
Style—Normal
Line heightYesNormal
Letter spacingYesNormal
Letter case—Normal
AlignmentYesNormal
Decoration—Normal, Hover, Focus
ColorsText—Normal, Hover, Focus
BackgroundType—Normal, Hover, Focus
Color / Gradient—Normal, Hover, Focus
Image—Normal
BorderBorder type—Normal, Hover, Focus
Border—Normal, Hover, Focus
RadiusYesNormal
Focus indicator—Focus
Box ShadowRemove shadow—Normal, Hover, Focus
Shadow layers—Normal, Hover, Focus
SpacingPaddingYesNormal
SizingWidthYesNormal
Max widthYesNormal
HeightYesNormal
Min width / Min height / Max heightYesNormal
EffectsOpacity (%)YesNormal, Hover, Focus

States for this part:

  • Hover — When the mouse pointer is over it. (Touch screens have no hover; they show the normal style.)
  • Focus — When it has keyboard focus — reached with the Tab key. Mouse clicks usually do not show focus styles.

Element: Block

The wrapper.

Styles-tab controls for “Block”
PanelControlPer deviceAvailable in states
BackgroundType—Normal
Color / Gradient—Normal
Image—Normal
BorderBorder type—Normal
Border—Normal
RadiusYesNormal
Box ShadowRemove shadow—Normal
Shadow layers—Normal
SpacingMarginYesNormal
PaddingYesNormal
SizingWidthYesNormal
Max widthYesNormal
HeightYesNormal
Min width / Min height / Max heightYesNormal
Block alignmentYesNormal
PositionPositionYesNormal
Top / Right / Bottom / LeftYesNormal
Z-indexYesNormal
OverflowYesNormal
TransformMove X / Move Y—Normal
Scale X / Scale Y—Normal
Rotate (°), Rotate X (°), Rotate Y (°)—Normal
Skew X (°) / Skew Y (°)—Normal
EffectsOpacity (%)YesNormal
State transition (ms)—Normal
Timing—Normal
VisibilityShow on Desktop / Tablet / Mobile—Normal

States: Normal only.

Element: Quantity

The quantity field.

Styles-tab controls for “Quantity”
PanelControlPer deviceAvailable in states
TypographyFont family—Normal
Font sizeYesNormal
Weight—Normal
Style—Normal
Line heightYesNormal
Letter spacingYesNormal
Letter case—Normal
AlignmentYesNormal
Decoration—Normal
ColorsText—Normal
BackgroundType—Normal
Color / Gradient—Normal
Image—Normal
BorderBorder type—Normal
Border—Normal
RadiusYesNormal
Focus indicator——
Box ShadowRemove shadow—Normal
Shadow layers—Normal
SpacingPaddingYesNormal
SizingWidthYesNormal
Max widthYesNormal
HeightYesNormal
Min width / Min height / Max heightYesNormal
EffectsOpacity (%)YesNormal

States: Normal only.

Element: Price

The price.

Styles-tab controls for “Price”
PanelControlPer deviceAvailable in states
TypographyFont family—Normal
Font sizeYesNormal
Weight—Normal
Style—Normal
Line heightYesNormal
Letter spacingYesNormal
Letter case—Normal
AlignmentYesNormal
Decoration—Normal
ColorsText—Normal

States: Normal only.

Responsive settings

Brigade Blocks uses three screen sizes: Desktop (wider than 1023px), Tablet (600–1023px) and Mobile (599px and narrower). Tablet and Mobile values are optional: when empty, the value of the next larger screen is used.

In the Styles tab, pick the Device first; these controls can then have a different value for that screen size: Font size, Line height, Letter spacing, Alignment, Radius, Padding, Width, Max width, Height, Min width / Min height / Max height, Opacity (%), Margin, Block alignment, Position, Top / Right / Bottom / Left, Z-index, Overflow.

The Visibility panel (Styles tab, Normal state) can hide the block entirely on Desktop, Tablet or Mobile.

Advanced options

  • HTML anchor (Advanced section of the Settings tab) — a unique name such as pricing, so you can link straight to this block with #pricing at the end of the page address (for example from a menu).
  • Additional CSS class(es) (Advanced section) — for custom CSS from your theme or the Site Editor. Separate several classes with spaces.
  • Custom attributes (Advanced section) — add data-*, title, aria-label, aria-describedby, lang or dir attributes. See Custom attributes.
  • State transition (Styles tab → Effects, Normal state) — how smoothly hover and focus styles animate.

How it works on your site

A real WooCommerce form: works without JavaScript (the page reloads with the item in the cart) and uses WooCommerce’s AJAX add to cart when available.

Accessibility

  • The button has WooCommerce’s descriptive label (“Add “Starter kit” to your cart”).
  • The quantity field has a label for screen readers.

Limitations and notes

  • Out-of-stock or unpurchasable products show WooCommerce’s “Read more” link.
  • Variable products link to the product page to choose options.

Troubleshooting

The block shows nothing.

No product is chosen and the page is not a product page. Pick a product in the settings.