Forums › Maximum Products per User for WooCommerce › Is it possible to set a maximum limit in a category per membership?
- Support forum for the Maximum Products per User for WooCommerce.
- This topic has 6 replies, 2 voices, and was last updated 5 years ago by
Tom Anbinder.
-
AuthorPosts
-
February 26, 2020 at 8:30 am #100357
gabriel_cc
ParticipantHi, pre-sale question,
We are using WooCommerce Subscriptions and WooCommerce Memberships for a private store, so only members can purchase products. We have 3 different monthly memberships, is it possible with this plugin to make products in a category sellable only a maximun number of times per membership?
So for example, subscribers to Silver membership can buy a maximun of 10 products from X category (the rest of the products can be bought normally) and subscribers to Gold membership can buy up to 15 products of that category.
After one month (as they are monthly memberships) subscribers should be able to buy again those products up to the maximun allowed by their membership.Is this possible with your plugin?
Thank you for your time
Gabriel
February 26, 2020 at 12:08 pm #100358Hi Gabriel,
Yes, the plugin can do that. What you need is to use “Formula” settings section (“WooCommerce > Settings > Maximum Products per User > Formula”) and set the “Formula” option there to something like this:
[alg_wc_mppu_max_qty max_qty="10" membership_plan="silver" term_id="101"] [alg_wc_mppu_max_qty max_qty="15" membership_plan="gold" term_id="101"]
As for resetting bought quantities on a monthly basis – you need to set “Date range” option in “General” settings section (“WooCommerce > Settings > Maximum Products per User > General”) to “Last 30 days” (or possibly “This month” if you want quantities to reset on the first day of each month instead of after 30 days).
Hope that clears it up. Please let me know if you have any questions.
February 27, 2020 at 11:49 am #100359gabriel_cc
ParticipantHello Tom,
Ive purchased the plugin and it works great. My only question is with the date range. Ive set it on “last 30 days”, but when does it start counting? Is it possible to have it tied to the moment the user bought the subscription? So they have 30 days from that moment to make the purchase.
Thank you!
February 27, 2020 at 9:05 pm #100360Hi Gabriel,
When you set the date range to “Last 30 days”, the plugin will check all orders from the last 30 days from the current moment (i.e. from the moment customer tries to buy a new product). As I understand, you need something different, i.e. the plugin should check if 30 days have passed since the customer bought a subscription and if so then apply zero max quantity for the product, is that correct? If that’s the case, I will have to check on how can I implement it in the plugin.
P.S. Thank you for the purchase.
February 28, 2020 at 12:10 pm #100361gabriel_cc
ParticipantHi Tom,
yes, as the subscriptions last for one month (as well as the memberships, their lenght is tied to the subscription’s length) the idea would be that the max quantities allowed to buy would also be tied to that time, so a month after purchasing the subscription/membership in this case.
As the subscription is autorenewed every month, if the user doesnt cancel it then he would be able to buy again the products for another month (to the max allowed in the formula as usual).Let me know if this would be possible,
thank you!February 28, 2020 at 2:40 pm #100362Hi Gabriel,
Ok, I think I got it this time. Please give me a couple of days to get back to you.
March 2, 2020 at 12:13 am #100363Hi Gabriel,
I was thinking about your task and I think I have a solution.
First of all, we should set Formula to something like this:
[alg_wc_mppu_max_qty max_qty="10" membership_plan="silver" term_id="101"] [alg_wc_mppu_max_qty max_qty="15" membership_plan="gold" term_id="102"] [alg_wc_mppu_max_qty max_qty="-1" term_id="101,102"]
This way users with active memberships will be able to order maximum
10
and15
products depending on their membership plan. And users with no active membership will be restricted from buying any products at all (i.e. max quantity-1
).Now if you set “Date range” to “Last 30 days”, the only problem we now have is that when checking orders for quantities, the plugin may check too many orders, i.e. orders from previous subscription. To fix that we will need to use
alg_wc_mppu_date_to_check
filter available in the plugin. Unfortunately, I don’t have “WooCommerce Memberships” plugin on my server, so I can’t give you the exact code, but if I could log in to your server (with FTP), I should be able to do it (if that’s possible my email is [email protected]). Or you can try to test it yourself with the code below. Generally the filter can be used to define custom date range, i.e.:add_filter( 'alg_wc_mppu_date_to_check', 'my_alg_wc_mppu_date_to_check', 10, 3 ); if ( ! function_exists( 'my_alg_wc_mppu_date_to_check' ) ) { /** * Maximum Products per User: Sets "date to check" to current user's membership start date. */ function my_alg_wc_mppu_date_to_check( $date_to_check, $date_range, $current_time ) { foreach ( wc_memberships_get_membership_plans() as $membership_plan_id => $membership_plan ) { if ( wc_memberships_is_user_active_member( get_current_user_id(), $membership_plan_id ) ) { $user_membership = wc_memberships()->get_user_memberships_instance()->get_user_membership( get_current_user_id(), $membership_plan_id ); $date_to_check = get_post_modified_time( 'U', false, $user_membership->post ); if ( ! $date_to_check ) { $date_to_check = $user_membership->get_start_date( 'timestamp' ); // Fallback } return $date_to_check; } } return $date_to_check; } }
Please let me know what you think.
-
AuthorPosts
- You must be logged in to reply to this topic.