Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Display correct block template when filtering by attribute #7640

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/BlockTemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,21 @@ public function render_block_template() {
$this->block_template_is_available( 'taxonomy-product_tag' )
) {
add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
} elseif ( taxonomy_is_product_attribute( get_query_var( 'taxonomy' ) ) &&
! BlockTemplateUtils::theme_has_template( 'archive-product' ) &&
$this->block_template_is_available( 'archive-product' )
) {
add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
} elseif (
( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) &&
! BlockTemplateUtils::theme_has_template( 'archive-product' ) &&
$this->block_template_is_available( 'archive-product' )
) {
add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
} else {
$queried_object = get_queried_object();

if ( taxonomy_is_product_attribute( $queried_object->slug ) &&
! BlockTemplateUtils::theme_has_template( 'archive-product' ) &&
$this->block_template_is_available( 'archive-product' )
) {
add_filter( 'woocommerce_has_block_template', '__return_true', 10, 0 );
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Templates/ProductAttributeTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ protected function init() {
* @param array $templates Templates that match the product attributes taxonomy.
*/
public function update_taxonomy_template_hierarchy( $templates ) {
if ( taxonomy_is_product_attribute( get_query_var( 'taxonomy' ) ) && wc_current_theme_is_fse_theme() ) {
$queried_object = get_queried_object();
if ( taxonomy_is_product_attribute( $queried_object->slug ) && wc_current_theme_is_fse_theme() ) {
array_unshift( $templates, self::SLUG );
}

Expand Down