From e20ee59681cba67b4d2b4d518b046ea80f3d746b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:19:08 +0800 Subject: [PATCH] Cherry pick 46429 into release/8.8 (#46473) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Prep for cherry pick 46429 --------- Co-authored-by: Albert Juhé Lluveras Co-authored-by: WooCommerce Bot --- plugins/woocommerce/readme.txt | 1 + .../src/Blocks/BlockTemplatesController.php | 25 +++++++++++++++++++ .../Templates/ProductCatalogTemplate.php | 21 ---------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/plugins/woocommerce/readme.txt b/plugins/woocommerce/readme.txt index d319cfc0de2c..8e01fcfbb705 100644 --- a/plugins/woocommerce/readme.txt +++ b/plugins/woocommerce/readme.txt @@ -169,6 +169,7 @@ WooCommerce comes with some sample data you can use to see how products look; im **WooCommerce** +* Fix - Fix wrong Shop title shown in classic themes after deleting the page [#46429](https://github.com/woocommerce/woocommerce/pull/46429) * Fix - Fixed an issue where orders could be placed when no shipping options were available [#46026](https://github.com/woocommerce/woocommerce/pull/46026) * Fix - Fix a bug where saved payment methods were not rendered correctly in the heckout block [#46019](https://github.com/woocommerce/woocommerce/pull/46019) * Fix - Removed count from is_array check to fix Analytics comparison filter. [#45939](https://github.com/woocommerce/woocommerce/pull/45939) 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; - } }