From 4bbd204b71a31b89b9caf41a9d105ae4dbbd4a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Juh=C3=A9=20Lluveras?= Date: Wed, 10 Apr 2024 19:45:34 +0200 Subject: [PATCH] Fix wrong Shop title shown in classic themes after deleting the page (#46429) * Fix wrong Shop title shown in classic themes after deleting the page * Add changelog file * Add explanatory comment --- .../changelog/2024-04-10-15-39-16-518263 | 4 +++ .../src/Blocks/BlockTemplatesController.php | 25 +++++++++++++++++++ .../Templates/ProductCatalogTemplate.php | 21 ---------------- 3 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 plugins/woocommerce/changelog/2024-04-10-15-39-16-518263 diff --git a/plugins/woocommerce/changelog/2024-04-10-15-39-16-518263 b/plugins/woocommerce/changelog/2024-04-10-15-39-16-518263 new file mode 100644 index 000000000000..5f543d51a6ba --- /dev/null +++ b/plugins/woocommerce/changelog/2024-04-10-15-39-16-518263 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix wrong Shop title shown in classic themes after deleting the page diff --git a/plugins/woocommerce/src/Blocks/BlockTemplatesController.php b/plugins/woocommerce/src/Blocks/BlockTemplatesController.php index 5bbabef303bc..26a5663d0cca 100644 --- a/plugins/woocommerce/src/Blocks/BlockTemplatesController.php +++ b/plugins/woocommerce/src/Blocks/BlockTemplatesController.php @@ -29,6 +29,7 @@ public function init() { add_filter( 'current_theme_supports-block-templates', array( $this, 'remove_block_template_support_for_shop_page' ) ); add_filter( 'taxonomy_template_hierarchy', array( $this, 'add_archive_product_to_eligible_for_fallback_templates' ), 10, 1 ); add_action( 'after_switch_theme', array( $this, 'check_should_use_blockified_product_grid_templates' ), 10, 2 ); + add_filter( 'post_type_archive_title', array( $this, 'update_product_archive_title' ), 10, 2 ); if ( wc_current_theme_is_fse_theme() ) { // By default, the Template Part Block only supports template parts that are in the current theme directory. @@ -558,6 +559,30 @@ public function block_template_is_available( $template_name, $template_type = 'w ) || $this->get_block_templates( array( $template_name ), $template_type ); } + /** + * Update the product archive title to "Shop". + * + * Attention: this method is run in classic themes as well, so it + * can't be moved to the ProductCatalogTemplate class. See: + * https://github.com/woocommerce/woocommerce/pull/46429 + * + * @param string $post_type_name Post type 'name' label. + * @param string $post_type Post type. + * + * @return string + */ + public function update_product_archive_title( $post_type_name, $post_type ) { + if ( + function_exists( 'is_shop' ) && + is_shop() && + 'product' === $post_type + ) { + return __( 'Shop', 'woocommerce' ); + } + + return $post_type_name; + } + /** * Remove the template panel from the Sidebar of the Shop page because * the Site Editor handles it. diff --git a/plugins/woocommerce/src/Blocks/Templates/ProductCatalogTemplate.php b/plugins/woocommerce/src/Blocks/Templates/ProductCatalogTemplate.php index 95c28f1aae13..53cea84fe73b 100644 --- a/plugins/woocommerce/src/Blocks/Templates/ProductCatalogTemplate.php +++ b/plugins/woocommerce/src/Blocks/Templates/ProductCatalogTemplate.php @@ -23,7 +23,6 @@ class ProductCatalogTemplate extends AbstractTemplate { */ public function init() { add_action( 'template_redirect', array( $this, 'render_block_template' ) ); - add_filter( 'post_type_archive_title', array( $this, 'update_product_archive_title' ), 10, 2 ); } /** @@ -58,24 +57,4 @@ public function render_block_template() { add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); } } - - /** - * Update the product archive title to "Shop". - * - * @param string $post_type_name Post type 'name' label. - * @param string $post_type Post type. - * - * @return string - */ - public function update_product_archive_title( $post_type_name, $post_type ) { - if ( - function_exists( 'is_shop' ) && - is_shop() && - 'product' === $post_type - ) { - return __( 'Shop', 'woocommerce' ); - } - - return $post_type_name; - } }