Back to Woocommerce

Compatibility Layer - AbstractTemplateCompatibility.php

plugins/woocommerce/client/blocks/docs/internal-developers/blockified-templates/compatibility-layer.md

10.9.06.3 KB
Original Source

Compatibility Layer - AbstractTemplateCompatibility.php

The Compatibility Layer ensures that blockified templates work correctly with extensions that use hooks to extend their behavior. It appends/pre-appends the corresponding hooks to each block. Also, it removes the default callbacks added to those hooks by WooCommerce.

A limitation of the Compatibility Layer is the order of hook execution. Blocks are rendered from the innermost to the outermost, meaning inner blocks are rendered first. This may cause the execution order of hooks to differ from that of the classic template.

The Compatibility Layer is disabled when either of classic template blocks are added on the page:

  • Product (Classic),
  • Product Attribute (Classic),
  • Product Category (Classic),
  • Product Tag (Classic),
  • Product's Custom Taxonomy (Classic),
  • Product Search Results (Classic),
  • Product Grid (Classic).

Please note these blocks represent classic templates. As an example, using Single Product block won't disable Compatibility Layer.

Furthermore, it is possible to disable the compatibility layer via the hook: woocommerce_disable_compatibility_layer.

Archive Product Templates - ArchiveProductTemplatesCompatibility

The compatibility is built around the Product Collection and Products (Beta) blocks because the loop is the main element of archive templates and hooks are placed inside and around the loop. The Compatibility Layer injects custom attributes for the Product Collection and Products (Beta) blocks that inherit query from the template and their inner blocks.

The following table shows where the hooks are injected into the page.

Hook NameBlock NamePosition
woocommerce_before_main_contentProductsbefore
woocommerce_after_main_contentProductsafter
woocommerce_before_shop_loop_item_titleProduct Titlebefore
woocommerce_shop_loop_item_titleProduct Titleafter
woocommerce_after_shop_loop_item_titleProduct Titlebefore
woocommerce_before_shop_loop_itemLoop Itembefore
woocommerce_after_shop_loop_itemLoop Itemafter
woocommerce_before_shop_loopProduct Templatebefore
woocommerce_after_shop_loopProduct Templateafter
woocommerce_no_products_foundNo Resultsbefore
woocommerce_archive_descriptionTerm Descriptionbefore

Single Product Templates - SingleProductTemplateCompatibility

The compatibility is built around the entire page. The classic Single Product Page has a main div with the class product that wraps all the elements, which has multiple classes: the style of the elements inside the wrapper is applied via CSS with the selector .product. For this reason, the Compatibility Layer wraps inside a div with the class product all the blocks related to the Single Product Template that aren’t interrupted by a template part.

The following table shows where the hooks are injected into the page.

HookBlock NamePosition
woocommerce_before_main_contentFirst block related to the Single Product Template (Product Image Gallery, Product Details, Add to Cart Form, Product Meta, Product Price, Breadcrumbs)before
woocommerce_after_main_contentLast block related to the Single Product Template (Product Image Gallery, Product Details, Add to Cart Form, Product Meta, Product Price, Breadcrumbs)after
woocommerce_sidebarLast block related to the Single Product Template (Product Image Gallery, Product Details, Add to Cart Form, Product Meta, Product Price, Breadcrumbs)after
woocommerce_before_single_productFirst block related to the Single Product Template (Product Image Gallery, Product Details, Add to Cart Form, Product Meta, Product Price, Breadcrumbs)before
woocommerce_before_single_product_summaryFirst block related to the Single Product Template (Product Image Gallery, Product Details, Add to Cart Form, Product Meta, Product Price, Breadcrumbs)before
woocommerce_single_product_summaryFirst core/post-excerpt or woocommerce/product-summary blockbefore
woocommerce_after_single_productLast block related to the Single Product Template (Product Image Gallery, Product Details, Add to Cart Form, Product Meta, Product Price, Breadcrumbs)after
woocommerce_product_meta_startProduct Metabefore
woocommerce_product_meta_endProduct Metaafter
woocommerce_shareProduct Detailsbefore
woocommerce_after_single_product_summaryProduct Detailsbefore