Skip Navigation

[Resolved] Show content only if product has more than 1 orders

This support ticket is created 7 years 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.

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 9 replies, has 2 voices.

Last updated by Nicholas 7 years ago.

Assisted by: Luo Yang.

Author
Posts
#590964

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/

#591100

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.

#591102

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?

#591122

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.

#591126

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.

#591135

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.

#591140
Screen Shot 2017-11-20 at 10.51.08 AM.png

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.

#591383

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.

#593075

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.

#593078

I guess this is solved.