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
This commit is contained in:
Albert Juhé Lluveras 2024-04-10 19:45:34 +02:00 committed by GitHub
parent 87f31f8ed0
commit 76bbd95db5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 21 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix wrong Shop title shown in classic themes after deleting the page

View File

@ -29,6 +29,7 @@ class BlockTemplatesController {
add_filter( 'current_theme_supports-block-templates', array( $this, 'remove_block_template_support_for_shop_page' ) ); 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_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_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() ) { if ( wc_current_theme_is_fse_theme() ) {
// By default, the Template Part Block only supports template parts that are in the current theme directory. // By default, the Template Part Block only supports template parts that are in the current theme directory.
@ -552,6 +553,30 @@ class BlockTemplatesController {
) || $this->get_block_templates( array( $template_name ), $template_type ); ) || $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 * Remove the template panel from the Sidebar of the Shop page because
* the Site Editor handles it. * the Site Editor handles it.

View File

@ -23,7 +23,6 @@ class ProductCatalogTemplate extends AbstractTemplate {
*/ */
public function init() { public function init() {
add_action( 'template_redirect', array( $this, 'render_block_template' ) ); 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 @@ class ProductCatalogTemplate extends AbstractTemplate {
add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 ); 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;
}
} }