Skip to content

Commit

Permalink
Fix wrong Shop title shown in classic themes after deleting the page (#…
Browse files Browse the repository at this point in the history
…46429)

* Fix wrong Shop title shown in classic themes after deleting the page

* Add changelog file

* Add explanatory comment
  • Loading branch information
Aljullu authored and WooCommerce Bot committed Apr 11, 2024
1 parent 22845c3 commit 4bbd204
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
4 changes: 4 additions & 0 deletions 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
25 changes: 25 additions & 0 deletions plugins/woocommerce/src/Blocks/BlockTemplatesController.php
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 4bbd204

Please sign in to comment.