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
ProductCatalogTemplate.php
90 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\WooCommerce\Blocks\Templates; |
| 4 | |
| 5 | use Automattic\WooCommerce\Blocks\Templates\ArchiveProductTemplatesCompatibility; |
| 6 | use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils; |
| 7 | |
| 8 | /** |
| 9 | * ProductCatalogTemplate class. |
| 10 | * |
| 11 | * @internal |
| 12 | */ |
| 13 | class ProductCatalogTemplate extends AbstractTemplate { |
| 14 | |
| 15 | /** |
| 16 | * The slug of the template. |
| 17 | * |
| 18 | * @var string |
| 19 | */ |
| 20 | const SLUG = 'archive-product'; |
| 21 | |
| 22 | /** |
| 23 | * Initialization method. |
| 24 | */ |
| 25 | public function init() { |
| 26 | add_action( 'template_redirect', array( $this, 'render_block_template' ) ); |
| 27 | add_filter( 'current_theme_supports-block-templates', array( $this, 'remove_block_template_support_for_shop_page' ) ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Returns the title of the template. |
| 32 | * |
| 33 | * @return string |
| 34 | */ |
| 35 | public function get_template_title() { |
| 36 | return _x( 'Product Catalog', 'Template name', 'woocommerce' ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Returns the description of the template. |
| 41 | * |
| 42 | * @return string |
| 43 | */ |
| 44 | public function get_template_description() { |
| 45 | return __( 'Displays your products.', 'woocommerce' ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Run template-specific logic when the query matches this template. |
| 50 | */ |
| 51 | public function render_block_template() { |
| 52 | if ( ! is_embed() && ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) && ! is_search() ) { |
| 53 | $compatibility_layer = new ArchiveProductTemplatesCompatibility(); |
| 54 | $compatibility_layer->init(); |
| 55 | |
| 56 | $templates = get_block_templates( array( 'slug__in' => array( self::SLUG ) ) ); |
| 57 | |
| 58 | if ( isset( $templates[0] ) && BlockTemplateUtils::template_has_legacy_template_block( $templates[0] ) ) { |
| 59 | add_filter( 'woocommerce_disable_compatibility_layer', '__return_true' ); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Remove the template panel from the Sidebar of the Shop page because |
| 66 | * the Site Editor handles it. |
| 67 | * |
| 68 | * @see https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/6278 |
| 69 | * |
| 70 | * @param bool $is_support Whether the active theme supports block templates. |
| 71 | * |
| 72 | * @return bool |
| 73 | */ |
| 74 | public function remove_block_template_support_for_shop_page( $is_support ) { |
| 75 | global $pagenow, $post; |
| 76 | |
| 77 | if ( |
| 78 | is_admin() && |
| 79 | 'post.php' === $pagenow && |
| 80 | function_exists( 'wc_get_page_id' ) && |
| 81 | is_a( $post, 'WP_Post' ) && |
| 82 | wc_get_page_id( 'shop' ) === $post->ID |
| 83 | ) { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | return $is_support; |
| 88 | } |
| 89 | } |
| 90 |