How do I set monthly limit of 3 products, each of which can only be bought once?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #100401
    Carlos Mendez
    Guest

    Hello:

    I have a question about the “Maximum Products per User for WooCommerce” plugin

    I’m creating an online store for downloadable products. The products can be downloaded for free but I would like to be able to limit the number of downloads of a single product for a single customer.

    That is, the customer can download a product once but can download products that he has not bought before.

    Can you do it with this plugin?

    A greeting

    #100402
    Carlos Jimenez
    Participant

    Hello:

    I bought the plug-in but I can’t get it to work the way I want it to.

    I’ll explain what I want to achieve and send a screenshot with the configuration:
    I have an online shop where all products are downloadable and with a price of 0. What I want to achieve is that only registered users can download 3 products monthly and that each product can be downloaded once during that period.

    However, in the orders it allows to add more than 3 products when they make a purchase.

    https://www.evernote.com/shard/s517/sh/31bf785a-0b09-067e-d86d-9edec55b1d57/41e73afcb8e4771d7e70dc7ac467df69

    #100403
    Tom Anbinder
    Moderator
    Plugin Support

    Hi Carlos,

    Sorry for the late reply.

    This can be done with our plugin, however, you will need to: a) add a small PHP snippet to your (child) theme’s functions.php file, and b) assign all your products to some category or tag.

    If that’s good enough – here is what you need to do:

    1. To limit the total number of products to 3 – as mentioned, you need to assign all your products to some category or tag. After that you need to enable “Per product category” (or “Per product tag”) option in “WooCommerce > Settings > Maximum Products per User > Limits”, and then set “Limit per user” option for that category (or tag) (in “Products > Categories > Your category > Edit”) to “3”.

    2. Now to add an additional “one product only” requirement, you will need to add this snippet:

    add_filter( 'alg_wc_mppu_check_quantities_for_product', 'my_alg_wc_mppu_limit_all_products_to_one', 10, 3 );
    if ( ! function_exists( 'my_alg_wc_mppu_limit_all_products_to_one' ) ) {
        /**
         * Sets max quantity for all products to one.
         */
        function my_alg_wc_mppu_limit_all_products_to_one( $is_valid, $core, $args ) {
            if ( $is_valid ) {
                $max_qty_all_products = 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_all_products ) {
                    if ( $args['do_add_notices'] ) {
                        $core->output_notice( $args['product_id'], $max_qty_all_products, $user_already_bought, $args['is_cart'], $args['cart_item_quantity'], 0 );
                    }
                    return false;
                }
            }
            return $is_valid;
        }
    }
    

    Please give it a try and let me know if you have any questions.

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