Top WooCommerce & WordPress Plugins › Forums › Maximum Products per User for WooCommerce › When the membership is renewed, how do I reset the limit?
- Support forum for the Maximum Products per User for WooCommerce.
- This topic has 1 reply, 2 voices, and was last updated 2 years, 11 months ago by
Tom Anbinder.
- AuthorPosts
- November 3, 2020 at 10:25 pm #100496
Marti
GuestHi,
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!November 5, 2020 at 1:21 am #100497Hi 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.
- AuthorPosts
- You must be logged in to reply to this topic.