• Resolved dgenc

    (@dgenc)


    Hello there,

    Can we prevent a user from opening a new one when they have an open ticket?

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • Anonymous User 15356385

    (@anonymized-15356385)

    Hi @dgenc

    It is not a configurable item, but the hooks, filters and functions do exist to add custom code to achieve this.

    The below example would achieve what you’re looking for if you only allow logged in users to log tickets. If you also allow guests, additional custom code would be needed.

    /**
     * Action to take when logged in customer exceeds max open ticket count.
     *
     * @return  mixed
     */
    function kbs_mh_max_ticket_notice() {
        ob_start(); ?>
        <p><?php _e( 'Max ticket count reached!', 'kb-support' ); ?></p>
        <?php echo ob_get_clean();
    } // kbs_mh_max_ticket_notice
    
    /**
     * Filter whether or not a logged in customer can submit a ticket.
     *
     * @param   bool    $can_submit True if they can submit, otherwise false
     * @return  bool    True if they can submit, otherwise false
     */
    function kbs_mh_no_submit_if_open( $can_submit ) {
        if ( is_user_logged_in() )   {
            $user_id      = get_current_user_id();
            $customer     = new KBS_Customer( $user_id, true );
            $ticket_query = new KBS_Tickets_Query( array(
                'number'   => 1, // Max 1 ticket open
                'status'   => 'open', // Use an array of statuses here as needed
                'customer' => $customer->id
            ) );
    
            $ticket_count = $ticket_query->get_tickets();
    
            if ( ! empty( $ticket_count ) ) {
                add_action( 'kbs_user_cannot_submit', 'kbs_mh_max_ticket_notice' );
                return false;
            }
        }
        
        return $can_submit;
    } // kbs_mh_no_submit_if_open
    add_filter( 'kbs_user_can_submit', 'kbs_mh_no_submit_if_open', 99 );
    Thread Starter dgenc

    (@dgenc)

    Hello,

    Thank you.

    Regards

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Blocking a new one with an open ticket’ is closed to new replies.