Is it possible to set a maximum limit in a category per membership?

Top WooCommerce & WordPress Plugins Forums Maximum Products per User for WooCommerce Is it possible to set a maximum limit in a category per membership?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #100357
    gabriel_cc
    Participant

    Hi, 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

    #100358
    Tom Anbinder
    Moderator
    Plugin Support

    Hi 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.

    #100359
    gabriel_cc
    Participant

    Hello 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!

    #100360
    Tom Anbinder
    Moderator
    Plugin Support

    Hi 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.

    #100361
    gabriel_cc
    Participant

    Hi 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!

    #100362
    Tom Anbinder
    Moderator
    Plugin Support

    Hi Gabriel,

    Ok, I think I got it this time. Please give me a couple of days to get back to you.

    #100363
    Tom Anbinder
    Moderator
    Plugin Support

    Hi 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 and 15 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.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.