Reputation: 1
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:
Upvotes: 0
Views: 41