I need to get a user's done purchases in the last month by USER ID in Woocommerce.
Users have levels (Gold, Silver):
- Gold members can purchase 4 items each month;
- Silver members can buy 1 item per month.
I need to check this before adding an item to the cart. I don't want to use a plugin for just this feature (which could not found, BTW).
Is that possible?
How can I achieve this?
Thanks
It's possible to get the total items count bought by the current customer in the past 30 days.
Here is the code of this function based on this answer:
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The function accept an optional
user_id
argument (if needed). For example for auser_id
with56
value, you will use the function, this way:The function will get the current user ID in
$user_id = get_current_user_id();
, if you dont set an argumentuser_id
value, this way:This code is tested and works.
References: Checking if customer has already bought something in WooCommerce