Lesson 5.1. WooCommerce Blocks and Block Themes

Goal

Find your way around WooCommerce blocks and the store templates of a block theme.

Key concepts

  • Store templates: single-product.html, archive-product.html, taxonomy-product_cat.html, page-cart.html, page-checkout.html, order-confirmation.html
  • Product Collection — the main block for product lists (instead of the deprecated Products blocks and shortcodes)
  • Product blocks work in context: price, button and image take postId from the template or the collection
  • Mini-Cart, Cart, Checkout — blocks with inner blocks that can be extended
  • Store patterns and theme.json for styles — no CSS overrides

Diagram

flowchart TB
  T["templates/archive-product.html"] --> PC["Product Collection"]
  PC --> PT["Product Template"]
  PT --> I["Product Image"]
  PT --> N["Product Title"]
  PT --> P["Product Price"]
  PT --> B["Product Button"]
  PT --> X["Your block<br/>usesContext: postId"]

Code

Product Collection in a category template (excerpt):

HTML
<!-- wp:woocommerce/product-collection {"query":{"perPage":12,"inherit":true,"woocommerceStockStatus":["instock","onbackorder"]},"collection":"woocommerce/product-collection/product-catalog"} -->
<div class="wp-block-woocommerce-product-collection">
	<!-- wp:woocommerce/product-template -->
		<!-- wp:woocommerce/product-image /-->
		<!-- wp:post-title {"isLink":true,"__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
		<!-- wp:woocommerce/product-price /-->
		<!-- wp:woocommerce/product-button /-->
	<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->

Price styles through theme.json, not CSS:

JSON
{
  "version": 3,
  "styles": {
    "blocks": {
      "woocommerce/product-price": {
        "typography": { "fontSize": "var(--wp--preset--font-size--large)", "fontWeight": "700" }
      }
    }
  }
}

Common mistakes

SymptomCauseFix
The theme's store template isn't appliedIt was changed in the Site Editor — the database version overrides the fileReset the template customization in the Site Editor
A shortcode product list isn't styled by blocksThe shortcode renders the classic templateProduct Collection
Your block doesn't see the product in a collectionNo usesContext: ["postId"]Add the context to block.json

Weak and strong answer

Question: How do you show 8 products on sale on the home page?

Weak answer. The

shortcode.

Strong answer. In a block theme — the Product Collection block with the On Sale collection and a limit of 8. It can be configured in the editor, supports the theme styles and caches the query. I keep the shortcode only for classic themes or old content.

Why the second is stronger: The candidate works with the modern tool and knows when to keep the old one.

Practice

Activate a block theme (Twenty Twenty-Five). Open the Product Catalog template in the Site Editor. Above the product list add a Product Collection "On sale" with 4 products. Export the theme and find how the changes look in the template HTML.

Interview Questions

A WooCommerce block for product lists with ready-made collections (new arrivals, on sale, best sellers, related products) and filters. The inner Product Template defines the product card from separate blocks.

In the database as a post of type wp_template. They take priority over the theme file until they are reset.

Store templates are edited without code, styles are centralized in theme.json, and block cart and checkout work by default. The price is a compatibility audit of plugins that depend on PHP templates.

Save your progress

Sign in or create a free account to mark lessons as completed and continue the whole course. You will come back to this lesson.