Is there any way to set up a query filter on the front-end that will allow the selection of Woocommerce product titles?
I'm setting up a view that displays all store orders. I'd like to add a front-end filter to allow the user to select a product and the results will then only show orders with that product among those ordered.
You've already gotten us custom code that displays Product Titles as a field within the page. That code is here:
<?php
/**
* New custom code snippet (replace this with snippet description).
*/
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
// Put the code of your snippet below this comment.
add_shortcode('get_ordered_product_titles', 'get_ordered_product_titles_func');
function get_ordered_product_titles_func() {
$product_ids = do_shortcode('[wpv-ordered-product-ids]');
if(!empty($product_ids)) {
$output = array();
$product_ids_arr = explode(',', $product_ids);
foreach ($product_ids_arr as $product_ids_arr_item) {
$output[] = do_shortcode('[wpv-post-link item="'.$product_ids_arr_item.'"]');
}
return implode(',<br>', $output);
}
}
So I'm guessing the filter will have to compare to the results produced by this code in some way.
Any help you can provide on this will be greatly appreciated.
Toolset Views provide a nice UI for generating WordPress queries (using the core WP_Query class) and then outputting the results.
Such queries can only filter by properties of the thing being queried (i.e. standard fields like post_date, custom fields of such posts, or taxonomy terms assigned to the posts).
So orders can only be filtered by such properties of orders.
But the products of an order are not stored in standard WordPress tables, they are stored in custom WooCommerce tables.
And so it is not possible to filter order posts by the products they contain using WP_Query (so you couldn't do it with regular code). To achieve that you would need to write custom SQL queries, and that's beyond the scope of support I'm afraid.
It gets even more complicated in that WooCommerce is switching over to custom tables for orders altogether (the orders themselves are currently stored in wp_posts). See hidden link
To be able to display orders at all with a View it will be necessary to continue to use the legacy mode of WC for storing orders.
OK. Is it possible to create individual Views for every product we have then instead of using a front-end filter? Or will I run into the same problem with that effort? If I create individual Views, I can set up pages for each product and then use a selection based menu to open each product page where these Views will be placed. In the Query Filter section, I am seeing "Customer Field - Product IDs" as one of the options. If I can use that to limit the output to Orders containing a single product ID, then I can do it that way.
Thanks for the info about changes coming to Woocommerce. I'll have to keep an eye out for that HPOS vs. Legacy setting.
Unfortunately I had a DEEPLY NEGATIVE experience the last time I hired one of your contractors that resulted in me losing thousands of future dollars through having a highly valued client of mine unethically stolen from me by that contractor. Until your management team implements my suggestion for including a ratings/reviews section on your contractor pages, I won't be able to take the risk of using one of them again because there is nothing present to dissuade any contractor from unethical behavior like that again. Sorry to have to say that here, but it is what happened. I filed a report against that contractor and your team did ultimately remove him, but no review/ratings system has been set up yet, so I can't take the chance on that happening to me again. I would MUCH rather hire one of your support team reps over the outside contractor, if that would be an option.
Your idea is to have individual pages for each product, each containing its own View, specific to that product, and the View will show orders that include that product?
That doesn't alter things in terms of the fundamental problem I described above. You have a product ID (determined by the page you are on instead of coming from a dropdown filter) and you want to filter orders to only return orders that include that product, but the products included in an order are not stored in wp_posts, wp_postmeta, or wp_term_relationships, they are stored in custom WC tables, and so are not accessible to WP_Query.
The only option would be to use the WC API to retrieve the order IDs that contain the specified product ID and then pass an array of these order IDs to the View query (using the wpv_filter_query hook) via the post__in attribute.
In that way, Views isn't really involved in the logic of the query, but is just being used to loop over the results and generate the desired output.
I'm sorry about your experience with a Toolset contractor. In support we are not in a position to undertake custom work, and while I cannot ordinarily recommend individual contractors I can point you to Beda Schmid who worked in Toolset Support for many years and knows the product inside out and who I can vouch for as scrupulously honest.
I will re-iterate that using Views to display orders obligates you to continue using the legacy storage mechanism of WooCommerce. If at any point you may want to switch to the newer HPOS storage you would need to replace anything developed with Views on these pages, and so another option would be to use a developer adept at WooCommerce to develop just these pages without Toolset.
OK, I'll contact Beda Schmid just to get a rough estimate on the cost and will pass along your recommended approach. That's definitely beyond my skill level to try .
We have Woocommerce Analytics that can get us the individual product info we're looking for but I was trying to build something using Toolset that might give us more flexibility and be more tailored to exactly what the client needed.
Do you plan to eventually update Toolset's Woocommerce functionality to be able to handle this new HPOS storage approach? I do have some store order report pages already built with Toolset for another client where this will impact them.
We do have an internal high-priority ticket to evaluate the effects of HPOS in the context of compatibility with Toolset plugins.
There is no time estimate to share at the moment, however, we announce all-important product updates and changes through our blog posts and newsletters.