No Results in WooCommerce Product Search

admin2025-01-07  8

When I try to create a grouped product, I type the field which searches for products but I am getting no results even though I should.

After looking at the request made from the API with this URL:

.php?term=earrings&action=woocommerce_json_search_products_and_variations&security=abcdefghij&exclude=201929&_fs_blog_admin=true

I confirmed the search is returning empty.

Does anyone knows how to fix this?

If any more information is needed please let me know and I will edit the question.

When I try to create a grouped product, I type the field which searches for products but I am getting no results even though I should.

After looking at the request made from the API with this URL:

https://domain.com/wp-admin/admin-ajax.php?term=earrings&action=woocommerce_json_search_products_and_variations&security=abcdefghij&exclude=201929&_fs_blog_admin=true

I confirmed the search is returning empty.

Does anyone knows how to fix this?

If any more information is needed please let me know and I will edit the question.

Share Improve this question asked Aug 16, 2020 at 9:35 OmerOmer 132 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I got this solution from https://stackoverflow.com/a/57218305/900557

Add this to your theme's functions.php

The Answer from Chandrakant Devani helped, but broke other searches in the admin. Adding an if seems to avoid breakages

if ( is_admin() && $query->is_main_query() && $query->query_vars['post_type'] == 'product')

full code:

add_action( 'pre_get_posts', 'products_pre_get_posts' );
function products_pre_get_posts( WP_Query $query ) {
    if ( is_admin() && $query->is_main_query() && $query->query_vars['post_type'] == 'product' ) {
        $query->set( 'tax_query', array(
            array(
                'taxonomy' => 'product_cat',
                'field'    => 'term_id',
                'terms'    => get_terms( array( 'taxonomy' => 'product_cat', 'fields' => 'ids' ) )
            )
        ) );
    }
}

I don't know enough about woocommerce to know why this is needed, but it fixed our problem

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736253628a138.html

最新回复(0)