diff --git a/plugins/woocommerce-blocks/src/BlockTemplatesController.php b/plugins/woocommerce-blocks/src/BlockTemplatesController.php index 38a10c96b49..16a02208b04 100644 --- a/plugins/woocommerce-blocks/src/BlockTemplatesController.php +++ b/plugins/woocommerce-blocks/src/BlockTemplatesController.php @@ -425,6 +425,11 @@ class BlockTemplatesController { $this->block_template_is_available( 'taxonomy-product_tag' ) ) { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); + } elseif ( taxonomy_is_product_attribute( get_query_var( 'taxonomy' ) ) && + ! BlockTemplateUtils::theme_has_template( 'archive-product' ) && + $this->block_template_is_available( 'archive-product' ) + ) { + add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } elseif ( ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) && ! BlockTemplateUtils::theme_has_template( 'archive-product' ) && diff --git a/plugins/woocommerce-blocks/src/Domain/Bootstrap.php b/plugins/woocommerce-blocks/src/Domain/Bootstrap.php index 7dd7f3b8074..186c18c52cc 100644 --- a/plugins/woocommerce-blocks/src/Domain/Bootstrap.php +++ b/plugins/woocommerce-blocks/src/Domain/Bootstrap.php @@ -22,6 +22,7 @@ use Automattic\WooCommerce\Blocks\Payments\Integrations\Cheque; use Automattic\WooCommerce\Blocks\Payments\Integrations\PayPal; use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; use Automattic\WooCommerce\Blocks\Registry\Container; +use Automattic\WooCommerce\Blocks\Templates\ProductAttributeTemplate; use Automattic\WooCommerce\StoreApi\StoreApi; use Automattic\WooCommerce\StoreApi\RoutesController; use Automattic\WooCommerce\StoreApi\SchemaController; @@ -116,6 +117,7 @@ class Bootstrap { $this->container->get( BlockTypesController::class ); $this->container->get( BlockTemplatesController::class ); $this->container->get( ProductSearchResultsTemplate::class ); + $this->container->get( ProductAttributeTemplate::class ); $this->container->get( ClassicTemplatesCompatibility::class ); if ( $this->package->feature()->is_feature_plugin_build() ) { $this->container->get( PaymentsApi::class ); @@ -249,6 +251,12 @@ class Bootstrap { return new ProductSearchResultsTemplate(); } ); + $this->container->register( + ProductAttributeTemplate::class, + function () { + return new ProductAttributeTemplate(); + } + ); $this->container->register( ClassicTemplatesCompatibility::class, function ( Container $container ) { diff --git a/plugins/woocommerce-blocks/src/Templates/ProductAttributeTemplate.php b/plugins/woocommerce-blocks/src/Templates/ProductAttributeTemplate.php new file mode 100644 index 00000000000..62dc2defb95 --- /dev/null +++ b/plugins/woocommerce-blocks/src/Templates/ProductAttributeTemplate.php @@ -0,0 +1,39 @@ +init(); + } + + /** + * Initialization method. + */ + protected function init() { + add_filter( 'taxonomy_template_hierarchy', array( $this, 'update_taxonomy_template_hierarchy' ), 10, 3 ); + } + + /** + * Render the Archive Product Template for product attributes. + * + * @param array $templates Templates that match the product attributes taxonomy. + */ + public function update_taxonomy_template_hierarchy( $templates ) { + if ( taxonomy_is_product_attribute( get_query_var( 'taxonomy' ) ) && wc_current_theme_is_fse_theme() ) { + array_unshift( $templates, self::SLUG ); + } + + return $templates; + } +}