• I would like to limit the amount of total products a user can buy to 4. No matter how many purchases the user makes, from one to 4, they can only let him buy 4 items or 4 products in total for the lifetime of the user.
    Thank you in advance,

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Algoritmika

    (@algoritmika)

    Hi @markelchroma,

    If you mean that you want to limit each product’s max qty to 4, then you simply need to enable “All products” checkbox, and set “Limit per user” option to 4 (both options are in “WooCommerce > Settings > Maximum Products per User > Limits”).

    Please let me know if I misunderstood the question.

    Plugin Author Algoritmika

    (@algoritmika)

    @markelchroma,

    After reading your question again, I’m now thinking maybe you had in mind, that you want to limit qty not for each product, but to all products at once? I.e. for example user can buy 1 pcs. of product A and 3 pcs. of product B? If that’s the case – unfortunately that is not possible at the moment, however there is a workaround – if you have a product tag, or product category that includes all your products, you can use “Per product tag” or “Per product category” plugin options, hope you get the idea.

    Thread Starter markelchroma

    (@markelchroma)

    Hi,
    No no, I would like to limit each product to 1 per user. And maximum 4 different products per user. Both conditions lifetime. For example:
    We have blueberries, lemons, bananas, tomatoes, and lettuces. Every user can by only one each and only 4 in total. So when one user buys one lemon, one banana and one tomato in one transaction, he only can buy or one lettuce or one blueberry next time. And thats all. After this second transaction, he cannot buy any product.

    Plugin Author Algoritmika

    (@algoritmika)

    @markelchroma,

    Ok, I got it this time. As mentioned, you can achieve max 4 by using “Per product tag” or “Per product category” options (please let me know if this approach is good enough for you). As for additionally setting max 1 for each product separately – not possible at the moment, but let me check the code – I think I can make this work in “Formula” section.

    Thread Starter markelchroma

    (@markelchroma)

    Ok, so I created a tag, and limited to 4.
    But do this limitation of 4, and the individual limit for each product will work lifetime for each user? I mean, if this user, that have bought 4 products try to buy one more in the next transaction, what happens? Could we block this? The same if the user buys one blueberry and tries to buy an other blueberry in the next transation.

    Plugin Author Algoritmika

    (@algoritmika)

    @markelchroma,

    Currently – no. But I’m already working on this. Will get back to you shortly.

    Thread Starter markelchroma

    (@markelchroma)

    Ok, so when do you think this could be done? Just to know, because we need this for a project that we are developing now.
    Thank you in advance

    Plugin Author Algoritmika

    (@algoritmika)

    Hi @markelchroma,

    One or two days at worst.

    Plugin Author Algoritmika

    (@algoritmika)

    Hi @markelchroma,

    Would it be ok for you to add a small PHP snippet to achieve what we need? If that’s ok, then you would need to limit tag to 4 (as we discussed before), and then add this code to your (child) theme’s functions.php file (this will additionally set any product’s max limit to 1):

    
    add_filter( 'alg_wc_mppu_check_quantities_for_product', 'my_custom_alg_wc_mppu_check_quantities_for_product', 10, 3 );
    if ( ! function_exists( 'my_custom_alg_wc_mppu_check_quantities_for_product' ) ) {
        function my_custom_alg_wc_mppu_check_quantities_for_product( $is_valid, $core, $args ) {
            if ( $is_valid ) {
                $max_qty = 1;
                $user_already_bought = $core->get_user_already_bought_qty( $args['product_id'], $args['current_user_id'], true );
                if ( ( $user_already_bought + $args['cart_item_quantity'] ) > $max_qty ) {
                    if ( $args['do_add_notices'] ) {
                        $core->output_notice( $args['product_id'], $max_qty, $user_already_bought, $args['is_cart'] );
                    }
                    return false;
                }
            }
            return $is_valid;
        }
    }
    

    Please let me know what you think.

    @algoritmika, I’m impressed by your prompt responses and free coding support on here!

    I have a question which I think you’ve answered here, but just need to confirm…

    The plugin description page doesn’t clarify this, but from this thread, my understanding is that the plugin can limit the total number of purchases a user is allowed to make across ALL products within a given category (i.e. it doesn’t necessarily limit how many purchases are possible of a given product from that category – at least until the category’s purchase limit has been reached).

    If this is correct, is this the ‘by category’ functionality that requires the PRO version?

    EDIT: (typo) necessarily*

    • This reply was modified 4 years, 9 months ago by ragrant0.
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Maximum product per user’ is closed to new replies.