Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter blondc_1

    (@blondc_1)

    Thanks for your time David, I ended up fixing this with some code I wrote after hours of trial and error. I’ll post it for others who are in the same bind.

    // Works only if login required
    function limit_active_apps( $reply_array ) {
    global $wpdb, $current_user, $appointments;
    $label = $wpdb->get_var(
                    "
                        SELECT meta_value FROM wp_usermeta WHERE meta_key = 'wp_capabilities' AND user_id = $current_user->ID
                    ");
    
    // Change statuses as required. i.e. remove pending condition if you wish
    
    $count = $wpdb->get_var( "SELECT COUNT(*) FROM " . $appointments->app_table . " WHERE user=".$current_user->ID." AND (status='pending' OR status='confirmed' OR status='paid' OR status='completed' ) and created > NOW() - INTERVAL 7 DAY " );
    
    if ( $count >= 2 AND (strpos($label,'userlabel_1') !== false) )
    		return array( 'error'=>'You have reached your maximum bookings, please wait 7 days from when you last booked' );
    
    if ( $count >= 1 AND (strpos($label,'userlabel_2') !== false) )
    		return array( 'error'=>'You have reached your maximum bookings, please wait 7 days from when you last booked' );
    		return $reply_array;
    }
    add_filter( 'app_pre_confirmation_reply', 'limit_active_apps' );
    
    ?>
    Thread Starter blondc_1

    (@blondc_1)

    Awesome! thanks David.
    It works well, just one extension I need for WordPress Access Areas
    Something along these lines:
    USER 1 can book 2 appointments
    if ( $count >= 2 || current_user_can(‘userlabel_1’))
    USER 2 can book 1 appointment
    else if ( $count >= 1 || current_user_can(‘userlabel_2’))

    Anyone know how to implement this idea?
    THANKS AGAIN!

Viewing 2 replies - 1 through 2 (of 2 total)