In the era of online courses, subscriptions, custom-made products and product personalization, it may happen a scenario where a user can only purchase a product once in their lifetime.
In this short tutorial, we will see how this is done.Clearly, the user must be logged in in order for the code to trigger, so this applies to stores that require checkout login in order to proceed with the order.
Continue reading WooCommerce: Only Allow to Buy a Product Once
This time around we’ll take a look at some SQL. As you know, WooCommerce orders (same as WooCommerce products) are stored in the WordPress database.
Instead of using complex PHP loops and conditionals, sometimes knowing a bit of database “reading” can help. I took some inspiration (because I don’t know everything by heart) from the “wc_customer_bought_product()” WooCommerce function, which contains some SQL to check if a user has purchased a given product.
I’ve played a little with the same SQL SELECT call, and managed to return the list of user email addresses who have purchased a specific product ID. If you’re ever going to need this, enjoy!
Continue reading WooCommerce: Get List of Users Who Purchased a Product ID
If you need to detect if a logged in user has purchased a certain product ID, this snippet will do the trick. You can use this for marketing (e.g. “Buy More of This!”) or for displaying special notices on the loop or the single product page. Enjoy!
Continue reading WooCommerce: Check If User Has Purchased Product