How can I set the time period limit for the current month for the 3 users roles?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #100876
    Brie
    Guest

    I have different user roles that have different purchase limits over different time periods.

    3 of my user roles ‘team’ ‘team2’ and ‘contractor’ have purchase limits within the current month which I am trying to set up.

    The rest of my user roles have purchase limits on specific products over a 3 month period (every quarter) which I currently have set up with a Custom Date Range of 12 weeks.

    I’m using the limits by formula (not including the product SKU’s as there are a ton) for the following:

    12 Weeks:

    [alg_wc_mppu limit="1" user_role="pewter,bronze,silver,gold,diamond,platinum,peels,resellerco,resellerlco,cowgirl" product_sku="X,X,X"]

    Current Month:

    [alg_wc_mppu limit="2" user_role="team, team2" product_sku="X,X,X"]
    
    [alg_wc_mppu limit="1" user_role="team, team2" product_sku="X,X,X"]
    
    [alg_wc_mppu limit="2" user_role="contractor" product_sku="X,X,X"]
    
    [alg_wc_mppu limit="1" user_role="contractor" product_sku="X,X,X"]
    

    How can I set the time period limit for the current month for the 3 users roles ‘team’ ‘team2’ and ‘contractor’?

    #100877
    Pablo
    Moderator
    Plugin Support

    Hi Brie,

    Sorry for the delay. I believe you’d have to use our alg_wc_mppu_date_to_check filter. Please, add this to your functions.php or to a custom plugin:

    add_filter( 'alg_wc_mppu_date_to_check', function ( $date_to_check, $date_range, $current_time, $product_or_term_id, $current_user_id, $is_product ) {
       if (
          ! empty( $user_meta = get_userdata( $current_user_id ) ) &&
          array_intersect( array( 'team', 'team2', 'contractor' ), $user_meta->roles )
       ) {
          $date_to_check = strtotime( date( 'Y-m-01' ), $current_time );
       }
       return $date_to_check;
    }, 10, 6 );

    If instead of the current month you’d like to check it against the last 30 days you could replace the $date_to_check line by this one:

    $date_to_check = ( $current_time - MONTH_IN_SECONDS );

    Let me know if it helps 😉

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