Hi Puneet,
Thank you for waiting.
I've performed some testing and research and here are my findings:
1. Using Toolset Views, you can create a post view that is set to show "Products" post type. To show only the products from a specific user, you can add a post author filter and select the option, based on how you're planning to use this view.
( screenshot: hidden link )
2. To show only orders from a specific product, there is no built-in filter available, but you'll need a custom shortcode that can use WooCommerce's own functions to check whether the current product exists or not in order.
( ref: https://wordpress.stackexchange.com/a/97228 )
For example, you can add the following code for a custom shortcode in your active theme's "functions.php" file:
add_shortcode( 'check_for_product_in_order', 'check_for_product_in_order_func');
function check_for_product_in_order_func( $atts ) {
$atts = shortcode_atts( array(
'product' => '',
'order' => '',
), $atts );
$order = wc_get_order( $atts['order'] );
$items = $order->get_items();
$found_items[] = '';
foreach ( $items as $item ) {
$product_name = $item->get_name();
$product_id = $item->get_product_id();
if($product_id == $atts['product']) {
$found_items[] = $product_id;
}
}
if(count($found_items) > 1) {
return 1;
}
else
{
return 0;
}
}
This shortcode will accept two parameters, "product" (id) and "order" (id) and will return 1 if the product is found in the order and 0 if it doesn't.
Important note: Please add "check_for_product_in_order" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
3. You'll create a new post view that will show "Orders" post type. It will show all the orders by default, but to limit its display only to orders which have a specific product in them, you can use the new custom shortcode in a conditional block so that it only displays the result, when the shortcode returns 1.
( ref: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/ )
You can wrap the loop item content of this view in a condition like this:
[wpv-conditional if="( '[check_for_product_in_order product="[wpv-attribute name="product"]" order="[wpv-post-id]"]' eq 1 )"]
Order Title: [wpv-post-title]<br>
Order ID: [wpv-post-id]<br>
[/wpv-conditional]
4. In the last step, you can place the shortcode for this order view, in the loop of the products view (created in step 1), like this:
[wpv-view name="view-to-show-orders-for-a-specific-product" product="[wpv-post-id]"]
Feel free to replace the slug of the view as per your website and note that we're passing the current product's ID to the nested orders view because we need it for the comparison in the conditional code block with the custom shortcode.
( ref: https://toolset.com/documentation/user-guides/passing-arguments-to-views/ )
I hope this helps and for more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
For assistance related to WooCommerce plugin's features and functions, you can consult its official support and documentation.
regards,
Waqar