Title: Change ticket status programmatically
Last modified: January 11, 2023

---

# Change ticket status programmatically

 *  Resolved [melisc](https://wordpress.org/support/users/melisc/)
 * (@melisc)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/change-ticket-status-programmatically/)
 * 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://wordpress.org/support/topic/how-can-i-automatically-change-the-status-of-a-ticket/](https://wordpress.org/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](https://wordpress.org/support/users/melisc/).

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

 *  [miliighe](https://wordpress.org/support/users/miliighe/)
 * (@miliighe)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/change-ticket-status-programmatically/#post-16365676)
 * 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](https://wordpress.org/support/users/melisc/)
 * (@melisc)
 * [3 years, 4 months ago](https://wordpress.org/support/topic/change-ticket-status-programmatically/#post-16368114)
 * Thank you so much! That worked 🙂
 * Here is the code in case it helps anyone else:
 *     ```wp-block-code
       $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.

 * ![](https://ps.w.org/supportcandy/assets/icon.svg?rev=2763565)
 * [SupportCandy - Helpdesk & Customer Support Ticket System](https://wordpress.org/plugins/supportcandy/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/supportcandy/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/supportcandy/)
 * [Active Topics](https://wordpress.org/support/plugin/supportcandy/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/supportcandy/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/supportcandy/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [melisc](https://wordpress.org/support/users/melisc/)
 * Last activity: [3 years, 4 months ago](https://wordpress.org/support/topic/change-ticket-status-programmatically/#post-16368114)
 * Status: resolved