Skip Navigation

[Resolved] Show Variation Product on WooCommerce shop and other archive pages

This support ticket is created 3 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Shane 3 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#2075943
Buy Fashion Gold.png

Tell us what you are trying to do?
Trying to show WooCommerce individual variations as simple product s on shop page which is powered by Toolset WooCommerce Views.

I'm able to achieve it using 'Display Variations as Separate Shop Products' plugin:
hidden link

What is the link to your site?
hidden link

Everything works as expected. However as soon as i use any filters (Toolset Views Filters), the individual variations don't show. Only the main products

I raised support with IconicWP and they told me that we need to:
Show the post type "product_variation" aside from the parent product "Product" while the filters are running.

Can you please help.

#2076193

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Shreyas,

Thank you for getting in touch.

Given that there isn't a way to do this with Toolset you can perhaps try to modify the post type query for views to include the product_variation post type.

Try using the Hook below.

add_filter( 'wpv_filter_query', 'cust_show_product_variations',99,3 );
 
function cust_show_product_variations( $query_args ,$view_settings,$view_id){
 
    if ( $view_id == '123') {
        $query_args['post_type'] = array('product', 'product_variation');
    }
    return $query_args;
}

Add this to your toolset custom code section in toolset->settings->custom codes and ensure its activated.

Replace the 123 with the ID of your view.

Please let me now if this helps.
Thanks,
Shane

#2077043
The Lab Mine custom code.png

Dear Shane,

I tried this code but it doesn't work.

You can check it on Shop page:
hidden link

Please also not that this is Toolset's WordPress Archive view and not just 'Views'.

PFA screenshot of attached custom code added.

#2077133

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Shreyas,

Given that this is an archive, perhaps you can try this.


function include_variation_in_archive( $query ) {
    if ( is_post_type_archive('product')) {
        $query->set( 'post_type', [ 'product', 'product_variation' ] );
    }
}
add_filter( 'pre_get_posts', 'include_variation_in_archive' );

This query should include the product variations to the archive. I cannot guarantee that this will work but you can give it a shot.

Thanks,
Shane

#2077303

Dear Shane,

The above code only works once the page is loaded but doesn't not work when any filters are triggered. How can we have the code work even when the filters are triggered?

#2077373

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Shreyas,

The main issue is that the "product_variation" post type is a hidden post type by Woocommerce. Our views plugin will only query posts types that are not hidden.

Even if we get them to display when the search is performed it will only be performed on the main product so you may not get the correct results.

Right now i'm setting the query on the archive to include the product_variations but there isn't a way to modify the search parameters for the archives.

Perhaps the only way to do this is for you to create a view, and add that view to a page that would act as your archive and redirect users to this page whenever they want to view the archive.

This way the view query can be modified to include the product_variation post type.

In a case like that then this code in the previous thread can be used.
https://toolset.com/forums/topic/show-variation-product-on-woocommerce-shop-and-other-archive-pages/#post-2076193

Please let me know what you think of this workaround.

Thanks,
Shane