• Resolved melisc

    (@melisc)


    Hello,

    I’m trying to change the status of a ticket programmatically. I tried following the instructions in this ticket but the plugin code seems to have changed since then: https://ww.wp.xz.cn/support/topic/how-can-i-automatically-change-the-status-of-a-ticket/

    Is there a new function like $wpscfunction->change_status( $ticket_id, $status_id); that would allow me to do this?

    I’ve tried using:

    do_action( ‘wpsc_change_ticket_status’, self::$ticket, $prev, $new, $customer_id );

    But I get the following error:

    Warning: foreach() argument must be of type array|object, string given in /var/www/mysite/docs/wp-content/plugins/supportcandy/includes/models/class-wpsc-agent.php on line 933

    Fatal error: Uncaught Error: Call to undefined method stdClass::get_current_read_permission_agents() in /var/www/mysite/docs/wp-content/plugins/supportcandy/includes/models/class-wpsc-agent.php:938 Stack trace: #0 /var/www/mysite/docs/wp-includes/class-wp-hook.php(308): WPSC_Agent::change_status() #1 /var/www/mysite/docs/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters() #2 /var/www/mysite/docs/wp-includes/plugin.php(517): WP_Hook->do_action() #3 /var/www/mysite/docs/wp-content/plugins/mysite-reminder/mysite-reminder.php(78): do_action() #4 /var/www/mysite/docs/wp-includes/class-wp-hook.php(308): ReminderEmails->reminder_emails_create_admin_page() #5 /var/www/mysite/docs/wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters() #6 /var/www/mysite/docs/wp-includes/plugin.php(517): WP_Hook->do_action() #7 /var/www/mysite/docs/wp-admin/admin.php(259): do_action() #8 /var/www/mysite/docs/wp-admin/tools.php(40): require_once(‘…’) #9 {main} thrown in /var/www/mysite/docs/wp-content/plugins/supportcandy/includes/models/class-wpsc-agent.php on line 938

    • This topic was modified 3 years, 4 months ago by melisc.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello there,

    You can use the following static function:

    WPSC_Individual_Ticket::change_status($prev_status_id, $new_status_id, $customer_id);

    I hope this will resovle the issue, please share the outcomes with us.

    Thread Starter melisc

    (@melisc)

    Thank you so much! That worked 🙂

    Here is the code in case it helps anyone else:

    $tickets = $wpdb->get_results( "SELECT * FROM wp_psmsc_tickets" );
    
    //print_r($tickets);
    
    foreach ($tickets as $ticket) {
    
    //print_r($ticket);
    
    $ticket_id = $ticket->id;
    
    $status = $ticket->status;
    
    $customer = $ticket->customer;
    
    $priority = $ticket->priority;
    
    $ticket = new WPSC_Ticket( $ticket_id );
    
    if ( ! $ticket->id ) {
    
    wp_send_json_error( 'Unauthorized request!', 401 );
    
    }
    
    WPSC_Individual_Ticket::$ticket = $ticket;
    
    WPSC_Individual_Ticket::change_status( $status, 3, $customer );
    
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Change ticket status programmatically’ is closed to new replies.