• Resolved mukhthar

    (@mukhthar)


    Hi,
    We are using Ajax search for woocommerce,We don’t want to show empty/zero price products on our site.
    We have added an add_action for woocommerce_product_query and it works fine on normal search.
    When we enter the search keyword, zero/empty price products are showing and when we hit enter the zero/empty products are not shown on search result page,
    Can you help me to remove the zero/empty price products form ajax results also
    Regards,
    Mukhthar

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Damian Góra

    (@damian-gora)

    Hi Mukhthar,

    It’s is possible by adding extra SQL queries, but I don’t recommend this way because of optimization issues. I think you can add all zero/empty products to a specific category or tag and exclude whole category or tag from a search using following code:

    
    add_action( 'pre_get_posts', function ( $query ) {
    
        if ( is_ajax() && defined( 'DGWT_WCAS_AJAX' ) ) {
    
            $tax_query = $query->get( 'tax_query' );
    
            if ( ! empty( $tax_query ) ) {
                $tax_query[] = array(
    		'taxonomy' => 'product_cat',
    	        'field'    => 'term_taxonomy_id',
    		'terms'    => array( 1 ), // Term ID to exclude
    		'operator' => 'NOT IN',
                );
    
                $query->set( 'tax_query', $tax_query );
    
    	}
        }
    
    }, 20 );
    

    Best
    Damian Góra

    Thread Starter mukhthar

    (@mukhthar)

    Hi,
    Thanks for the reply,Is there any way to exclude zero prices without tag or category.On our case price is updated externally and its more complicated to assign a tag/catgeory

    regards,
    Mukhthar

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Remove empty/zero price products from search’ is closed to new replies.