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