Aakash Gupta
Aakash Gupta

Reputation: 1

How to correctly display woocommerce product variations in catalog?

On my woocommerce store I want to display product variations on the shop page and other catalog/archive pages like category page, etc.

I am using pre_get_posts hook to modify $query as below but some subcategories ('sheer-curtains', 'blackout-curtains') are not displaying variations only parent products, and all other categories and subcategories are displaying variations correctly.

Only thing I can recognize is that the subcategories not working were created recently and products added to them recently.

add_action('pre_get_posts', 'modify_products_query_for_color_variations',20);

function modify_products_query_for_color_variations($q) {   
    if (!is_admin() && $q->is_main_query() && (is_shop() || is_product_category())){
        $q->set('post_type', ['product','product_variation']);
    }
}

What I've Tried:

  1. Confirmed that the products in the problematic subcategories have variations, and look same as other non-problematic subcategories.
  2. Flushed permalinks by re-saving the settings in WooCommerce > Settings > Permalinks.
  3. Cleared transients, regenerated product lookup and database tables.
  4. Matched the query object generated using custom_log from many subcategories, and they are exactly same with just category name different.

Upvotes: 0

Views: 41

Answers (0)

Related Questions