Home Forums WoodMart support forum Exclude products without featured image from woodmart blocks product query

Exclude products without featured image from woodmart blocks product query

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #698610

    rdbm
    Participant

    Hello,

    I am currently using the Woodmart product blocks feature to display products on my site. I want to modify the general product query used by these blocks so that products without a featured image are excluded from the results.

    I’ve tried the following code using the woocommerce_product_query action:

    add_action('woocommerce_product_query', 'exclude_products_without_featured_image');
    function exclude_products_without_featured_image($q) {
        $meta_query = $q->get('meta_query');
        $meta_query[] = array(
            'key'     => '_thumbnail_id',
            'compare' => 'EXISTS',
        );
        $q->set('meta_query', $meta_query);
    }

    This approach works for the main WooCommerce product query, but users still see products with placeholder images inside Woodmart product blocks.

    Is there a recommended way or filter hook specific to Woodmart blocks to exclude products without a featured image? Or could you provide guidance or relevant code snippets to customize the product query these blocks use to avoid displaying products without thumbnails?

    Thank you for your assistance!
    Rob

    #698710

    Artem Temos
    Keymaster

    Hello,

    Thank you so much for purchasing our theme and contacting our support center.

    The code you sent works for the main WooCommerce query. If you want to filter our theme’s products block, you can use the following filter woodmart_product_element_query_args. Check how it works in the file woodmart/inc/shortcodes/products.php.

    Kind Regards
    XTemos Studio

Viewing 2 posts - 1 through 2 (of 2 total)