When the membership is renewed, how do I reset the limit?

Top WooCommerce & WordPress Plugins Forums Maximum Products per User for WooCommerce When the membership is renewed, how do I reset the limit?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #100496
    Marti
    Guest

    Hi,

    Object: limit reset when membership renewed

    Wow, great plugin! I am interested in your WC Memberships integration, but have a question:

    When using your formula to limit i.e to 8 purchases of a specific product for a specific membership:
    If membership expires, and user becomes member again later, I need the limit to be reset. Is this possible? or event the default behavior? Thank you!

    #100497
    Tom Anbinder
    Moderator
    Plugin Support

    Hi Marti,

    Sorry for the late reply.

    Thank you.

    That’s possible, however, you will need to add a small PHP snippet to your site. If that’s good enough, please add the snippet below to your (child) theme’s functions.php file. Please note that for this filter to be applied, “Date range” option (in “WooCommerce > Settings > Maximum Products per User > General”) must not be set to “Lifetime”.

    add_filter( 'alg_wc_mppu_date_to_check', 'my_alg_wc_mppu_date_to_check', 10, 6 );
    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, $product_or_term_id, $current_user_id, $is_product ) {
            foreach ( wc_memberships_get_membership_plans() as $membership_plan_id => $membership_plan ) {
                if ( wc_memberships_is_user_active_member( $current_user_id, $membership_plan_id ) ) {
                    $user_membership = wc_memberships()->get_user_memberships_instance()->get_user_membership( $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 give it a try and let me know if something is not working as expected, or if you have any questions.

    P.S. And if you like the plugin, please consider leaving me a rating.

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