Gutenberg for the Store

9

questions

How do you pass data from PHP to the store?

wp_interactivity_state( 'namespace', [...] ) — global state; wp_interactivity_data_wp_context() — the local context of a specific block.

What is block context?

A way to pass data from a parent block to its children: providesContext on the parent, usesContext on the child. Product Template passes the postId of every product.

What is Product Collection?

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.

What is the Interactivity API?

The WordPress standard for frontend interactivity: the server renders HTML with data-wp-* directives, and a small runtime binds them to a JS store. Blocks on the same page can share state.

When should a block be dynamic?

When the data changes independently of content editing: prices, stock, user data, post lists. Then render.php generates the HTML on every request.

Where are template changes made in the Site Editor stored?

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

Why get_block_wrapper_attributes()?

It adds the classes and styles from supports (colors, spacing, alignment) to the block wrapper. Without it the inspector settings don't reach the markup.

Why is a block theme better for a store?

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.

Why is it better than jQuery or your own React?

No duplicated markup on the client, it works with server rendering, and the scripts are modules loaded only with the block. State can be passed from PHP through wp_interactivity_state().