woocommerce/plugins/woocommerce-blocks/docs/internal-developers/templates
Alba Rincón 304f2c3c23 Make `Products by category/tag/attribute` fallback to the `Product catalog` template (https://github.com/woocommerce/woocommerce-blocks/pull/7712)
* Add archive-product to the hierarchy

* Fallback to archive-product and get titles from blocks if the templates from theme don't have one

* Rename function

* Fix comment

* Add fallbacks to the db and blocks versions

* Add missing product attribute blockified template

* Update docs

* Add comment and fix comment type on wp_template

* Replate template name if we know the template in blocks

* Add comment and fix linting error

* Fix archive-product template

* Clone the fallback template from db to show them in the template lsit

* Return the fallback template when querying for a single template

* Remove unneeded condition

* Use wp function instead of gutenberg one

* Fix tests

* Fix tests on Product Catalog templates

It was checking a single product for the customization, but it should check the /shop page

* Disable tests related with deleteAllTemplates function
2022-11-24 16:45:39 +01:00
..
assets Improve the structure of the WooCommerce Blocks Handbook (https://github.com/woocommerce/woocommerce-blocks/pull/6429) 2022-06-09 17:52:19 +02:00
README.md Add woocommerce_blocks_loaded hook information to actions doc (https://github.com/woocommerce/woocommerce-blocks/pull/7600) 2022-11-10 09:52:04 +01:00
block-template-controller.md Make `Products by category/tag/attribute` fallback to the `Product catalog` template (https://github.com/woocommerce/woocommerce-blocks/pull/7712) 2022-11-24 16:45:39 +01:00
classic-template.md Add woocommerce_blocks_loaded hook information to actions doc (https://github.com/woocommerce/woocommerce-blocks/pull/7600) 2022-11-10 09:52:04 +01:00

README.md

Templates

Table of contents

This page includes documentation related to WooCommerce Block Templates.

Overview

WooCommerce Block Templates are a collection of WooCommerce Core templates for the WordPress Full Site Editing experience introduced in WordPress 5.9. You can customize these templates in the Site Editor.

You can read more about the Full Site Editing (FSE) experience here.

Requirements

Software Minimum Version
WordPress 5.9
WooCommerce 6.0
Theme Any block theme

Technical Overview

The Problem

Currently, the FSE feature does not accommodate loading block templates from plugins such as WooCommerce (or WooCommerce Blocks). Instead, all template files loaded natively must be present within the active theme's templates folder. When the active block theme doesn't come with WooCommerce specific templates, we want to be able to provide sensible defaults, though.

The Solution

We created a custom solution which involves a handful of files (listed in the below table) that are responsible for both making the templates available as a block template, and rendering it on the front-end.

The BlockTemplateController.php is primarily responsible for hooking into both WordPress core, and WooCommerce core filters to load WooCommerce templates in the Site Editor and on the front-end. It is in this class where the majority of the logic is handled.

Some things to be aware of

  • Individual templates are represented by a placeholder block within the Site Editor until we can 'block-ify' these. This is the long-term goal. Until then users will be able to customize templates by adding blocks above and below the placeholder.
  • At the beginning of the project, we unintentionally used the incorrect WooCommerce plugin slug. This has resulted in us maintaining both the incorrect and correct slugs. We reference these via BlockTemplateUtils::DEPRECATED_PLUGIN_SLUG and BlockTemplateUtils::PLUGIN_SLUG. More information on that here.
  • If a theme has a archive-product.html template file, but does not have any taxonomy related files. We will automatically duplicate their themes archive-product.html file in place of these taxonomy files within BlockTemplateController->get_block_file_template().
  • In BlockTemplateController->get_block_templates() we filter out templates in production that are behind a feature flag. These will be available in development, but will be absent in production unless the feature flag is removed.
File Description Source Docs
templates/templates/* Location in the filesystem where WooCommerce block template HTML files are stored. Source files
classic-template/* The JavaScript block rendered in the Site Editor. This is a server-side rendered component which is handled by ClassicTemplate.php Source file README
ClassicTemplate.php Class used to setup the block on the server-side and render the correct template Source file README
BlockTemplateController.php Class which contains all the business logic which loads the templates into the Site Editor or on the front-end through various hooks available in WordPress & WooCommerce core. Source file README
BlockTemplateUtils.php Class containing a collection of useful utility methods. Source file