Tell us what you are trying to do?
Hello I'd like to show certain content on product pages only if the product has more than or equal to one orders
How's this possible?
I.e.: Nobody has ordered this product yet. Be the first one to buy it.
Is there any documentation that you are following?
https://toolset.com/learn/create-an-ecommerce-wordpress-site/displaying-more-information-from-woocommerce/how-to-display-customers-who-also-bought-the-product/
Dear Nicholas,
There isn't such a built-in feature within Views plugin, Woocommerce plugin is using a custom database table "wp_woocommerce_order_items" to store the order's items, which is out the range of WordPress, you can try other custom codes solutions, for example, this thread:
https://stackoverflow.com/questions/40280692/how-to-check-how-many-times-a-product-has-been-bought-by-a-customer
For your reference.
Thank you. So when is this part in the view actually displayed then?
https://toolset.com/learn/create-an-ecommerce-wordpress-site/displaying-more-information-from-woocommerce/how-to-display-customers-who-also-bought-the-product/
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
I was wondering because if there is no order this doesn't show up?
Do you you know why?
Please check the document you mentioned above:
https://toolset.com/learn/create-an-ecommerce-wordpress-site/displaying-more-information-from-woocommerce/how-to-display-customers-who-also-bought-the-product/
screenshot:
hidden link
It is using custom PHP function wpv_woo_product_belongs_to_this_order() to check if current order post is belongs to the
current the product, then display the order's fields, it is not the built-in feature of Views plugin.
And I don't think it is a good idea to list all order posts in a view, then check each order is belongs to the current product post, if there are lots of order posts, it will conduct a performance problem.
You said "And I don't think it is a good idea to list all order posts in a view, then check each order is belongs to the current product post, if there are lots of order posts, it will conduct a performance problem."
Hm...really? Even if I use pagination? How many orders are recommend? What will not cause a performance problem?
Also I don't think you answered my question above as I still don't know why the view doesn't display "No items found" if there is no order for the product yet.
Q1) Even if I use pagination?
if you are using pagination, it will only works for "order" posts of current page, it can not check other page's "order" posts, I suggest you try it yourself first.
Q2) why the view doesn't display "No items found" if there is no order for the product yet.
If you see the message "No items found", that means there isn't any result satisfied the Views filters, to debug this problem, you can simply edit the problem view, remove the filters one by one, check which filter conduct this problem.
sorry I think I am referring to the wrong documentation. It's the other document as there seems to be a misunderstanding.
Attached you'll find a screenshot of my filter.
It's only one.
I can't why the view doesn't display "No items found" if there is no order for the product yet.
My content template looks exactly like the screenshot you sent before.
Everything is exactly the same as in this doc https://toolset.com/learn/create-an-ecommerce-wordpress-site/displaying-more-information-from-woocommerce/how-to-display-customers-who-also-bought-the-product/
But if there is not order yet the view just doesn't display "No items found" if there is no order for the product yet.
In your screenshot, there is only one filter, which work for this:
If the order post has been marked as completed, then display it
So the view will be able to query all completed order posts, including orders of other products, that will conduct the result as you mentioned above:
It doesn't display "No items found" if there is no order for the product yet.
Ooooh so it will query also orders of other posts?
Even if I wrap the loop in a conditional like so
[wpv-conditional if="( wpv_woo_product_belongs_to_this_order() eq '1' )"]
Yeah that makes sense I guess.