Skip Navigation

[Resolved] How to add product variation to search results (Toolset Blocks)

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.

This topic contains 5 replies, has 2 voices.

Last updated by keijoM 1 year ago.

Author
Posts
#2595985
toolset-blocks-image.png

Tell us what you are trying to do?
I will try to add variable products in search result.

Is there any documentation that you are following?
yes, relevanssi is configured and it work well. It will found variable products.
Relevanssi support check this issue and they think, that problem can be post_type limitation in the search.

What is the link to your site?
dev.stepsystems.fi/tuotehaku/

Is there some introduction how to add variable products in search?

Check attachment: toolset-blocks-image.png

Br. Keijo

#2596285

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

Product variations are a different post type than products, details of which are shown when displaying the parent they pertain to, and it is not envisaged that a query for product posts would also return product_variation posts.

As it is not a public post type it is not available to choose from the Views UI when specifying the content to query.

You could try to use the Views API, in particular the wpv_filter_query hook, to modify the query arguments and add product_variation to the post_type argument so that they were returned by the View query.

See https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#2596615

Hello,

May i have example or introduction how to implement Views API and wpv_filter_query hook?

I think i am not alone with this issue.

Br. Keijo

#2596769

Hello,

Is it possible to get the product variation SKU in the part of search results? Then it is possible to get results typing "product variation SKU" in search filed.

I think this product variation SKU is the missing piece..

Br. Keijo

#2596973

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

If the View is querying products then it can only return product posts, not product_variation posts.

You can include product_variation posts via the wpv_filter_query as shown below.

Create a code snippet at Toolset > Settings > Custom Code and add the following (you will need to edit the View ID from the example 123; if you want to apply this to more than one View you can provide a comma-separated list of View IDs. To see the View ID go to Toolset > Views. If you cannot see that menu option—you are working solely with the block-editor interface—then go to Toolset > Settings and specify that you want to use both the block and legacy interfaces).

function tssupp_filter_query($view_args, $view_settings, $view_id)
{

    if ( in_array($view_id, array( 123 )) ) {

        $view_args['post_type'][] = 'product_variation';
    }

    return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_filter_query', 101, 3);

That would include both the parent product and the child variations in the results.

#2597279

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.