AbstractPageTemplate.php
1 year ago
AbstractTemplate.php
10 months ago
AbstractTemplateCompatibility.php
1 year ago
AbstractTemplatePart.php
2 years ago
AbstractTemplateWithFallback.php
7 months ago
ArchiveProductTemplatesCompatibility.php
1 year ago
CartTemplate.php
10 months ago
CheckoutHeaderTemplate.php
2 years ago
CheckoutTemplate.php
10 months ago
ClassicTemplatesCompatibility.php
1 year ago
ComingSoonSocialLinksTemplate.php
1 year ago
ComingSoonTemplate.php
1 year ago
ExternalProductAddToCartWithOptionsTemplate.php
1 year ago
GroupedProductAddToCartWithOptionsTemplate.php
1 year ago
MiniCartTemplate.php
2 years ago
OrderConfirmationTemplate.php
1 year ago
ProductAttributeTemplate.php
7 months ago
ProductBrandTemplate.php
7 months ago
ProductCatalogTemplate.php
7 months ago
ProductCategoryTemplate.php
7 months ago
ProductSearchResultsTemplate.php
7 months ago
ProductTagTemplate.php
7 months ago
SimpleProductAddToCartWithOptionsTemplate.php
1 year ago
SingleProductTemplate.php
2 months ago
SingleProductTemplateCompatibility.php
10 months ago
VariableProductAddToCartWithOptionsTemplate.php
1 year ago
ProductBrandTemplate.php
72 lines
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | namespace Automattic\WooCommerce\Blocks\Templates; |
| 4 | |
| 5 | use Automattic\WooCommerce\Blocks\Templates\ArchiveProductTemplatesCompatibility; |
| 6 | use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils; |
| 7 | |
| 8 | /** |
| 9 | * ProductBrandTemplate class. |
| 10 | * |
| 11 | * @internal |
| 12 | */ |
| 13 | class ProductBrandTemplate extends AbstractTemplateWithFallback { |
| 14 | |
| 15 | /** |
| 16 | * The slug of the template. |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | const SLUG = 'taxonomy-product_brand'; |
| 21 | |
| 22 | /** |
| 23 | * The template used as a fallback if that one is customized. |
| 24 | * |
| 25 | * @var string |
| 26 | */ |
| 27 | public string $fallback_template = ProductCatalogTemplate::SLUG; |
| 28 | |
| 29 | /** |
| 30 | * Whether this is a taxonomy template. |
| 31 | * |
| 32 | * @var bool |
| 33 | */ |
| 34 | public bool $is_taxonomy_template = true; |
| 35 | |
| 36 | /** |
| 37 | * Returns the title of the template. |
| 38 | * |
| 39 | * @return string |
| 40 | */ |
| 41 | public function get_template_title() { |
| 42 | return _x( 'Products by Brand', 'Template name', 'woocommerce' ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Returns the description of the template. |
| 47 | * |
| 48 | * @return string |
| 49 | */ |
| 50 | public function get_template_description() { |
| 51 | return __( 'Displays products filtered by a brand.', 'woocommerce' ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Run template-specific logic when the query matches this template. |
| 56 | */ |
| 57 | public function render_block_template() { |
| 58 | if ( ! is_embed() && is_product_taxonomy() && is_tax( 'product_brand' ) ) { |
| 59 | $compatibility_layer = new ArchiveProductTemplatesCompatibility(); |
| 60 | $compatibility_layer->init(); |
| 61 | |
| 62 | $templates = get_block_templates( array( 'slug__in' => array( self::SLUG ) ) ); |
| 63 | |
| 64 | if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) { |
| 65 | add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' ); |
| 66 | } |
| 67 | |
| 68 | add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 |