WooCommerce: Only Allow to Buy a Product Once

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.

Enjoy!

Continue reading WooCommerce: Only Allow to Buy a Product Once

WooCommerce: Get List of Users Who Purchased a Product ID

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