- This topic has 10 replies, 4 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
March 13, 2023 at 1:05 pm #2566446
René
Hello, how can I disable the loop template for the WooCommerce product search (WooCommerce Block)? For the normal search, however, the template should remain.
March 13, 2023 at 6:24 pm #2566653Fernando Customer Support
Hi Rene,
Can you try adding this snippet?:
add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 100 === $element_id && is_search && is_woocommerce() ) { $display = false; } return $display; }, 10, 2 );Replace 100 with the Loop Element’s ID.
Getting the Element ID: https://share.getcloudapp.com/YEuDdrnQ
March 14, 2023 at 12:19 pm #2567716René
Thank you, but this does not work :/
March 14, 2023 at 12:29 pm #2567728Ying
StaffCustomer SupportCan you link us to a Woo product search result page?
March 14, 2023 at 12:32 pm #2567729René
Hey, yes. Check the private information
I already changed the “is_search” to “is_search()”.
March 14, 2023 at 12:34 pm #2567731René
Deleted
March 14, 2023 at 3:48 pm #2567848Ying
StaffCustomer SupportYou have a query loop added in the product search before the breadcrumbs, but the product search result itself is not using a loop template.
So which part are you referring to as the loop template in your question?
March 15, 2023 at 12:46 am #2568150René
the product search results are influenced by the loop template. If I disable the loop template, the search results are displayed like products.
March 15, 2023 at 5:09 am #2568397David
StaffCustomer SupportHi there,
the Loop Template you have, what are the display rules? As you need to exclude the
product archivefrom those.
if that causes a different issue then try this snippet where we check the search is showing only the product archive.add_filter( 'generate_element_display', function( $display, $element_id ) { if ( 100 === $element_id && is_search() && is_post_type_archive( 'product' ) ) { $display = false; } return $display; }, 10, 2 );March 15, 2023 at 6:16 am #2568477René
Our programmer looked at this and solved it as follows. I’m sure I’m not the only one with this problem. Maybe an idea for one of the next updates.
Replace 1691 with your Element ID (Loop Template)
add_filter( 'generate_element_display', function( $display, $element_id ) { if($display){ if(is_search()){ if ( ( get_post_type() === 'product') && (1691 === $element_id)) { return false; } } } return $display; }, 10, 2 ); add_action('pre_get_posts', 'remove_product_if_not_in_url'); function remove_product_if_not_in_url($query) { if (is_admin() || !$query->is_main_query() || !$query->is_search()) { return $query; } if($query->is_search()){ // Test if the query exists at the URL if ( get_query_var('post_type') && get_query_var('post_type') == 'product' ) { return $query; } else { $cpt = [ 'post', 'page' ]; $query->set('post_type', $cpt); return $query; } } }March 15, 2023 at 6:49 am #2568515David
StaffCustomer SupportGlad to hear you got a working solution.
-
AuthorPosts
- You must be logged in to reply to this topic.