Singular_Order_Page::update_order_status( int $post_id, WP_Post $post )

Updates the order status.


Parameters

$post_id

(int) (Required) The post ID.

$post

(WP_Post) (Required) The post object.


Top ↑

Return

(void)


Top ↑

Source

File: src/Tickets/Commerce/Admin/Singular_Order_Page.php

	public function update_order_status( $post_id, $post ) {
		if ( Order::POSTTYPE !== $post->post_type ) {
			return;
		}

		if ( ! is_admin() ) {
			return;
		}

		if ( ! current_user_can( 'edit_post', $post_id ) ) {
			return;
		}

		$new_status = tribe_get_request_var( 'tribe-tickets-commerce-status', false );

		if ( ! $new_status ) {
			return;
		}

		$order = tec_tc_get_order( $post );

		if ( ! $order instanceof WP_Post ) {
			return;
		}

		$new_status = tribe( Status_Handler::class )->get_by_slug( $new_status );

		if ( $new_status->get_wp_slug() === $order->post_status ) {
			return;
		}

		$current_status = tribe( Status_Handler::class )->get_by_wp_slug( $order->post_status );

		if ( ! $current_status->can_apply_to( $order, $new_status ) ) {
			$this->redirect_with_message( $post_id, 1001 );
			return;
		}

		$result = tribe( Order::class )->modify_status( $order->ID, $new_status->get_slug() );

		if ( ! $result || is_wp_error( $result ) ) {
			$this->redirect_with_message( $post_id, 1001 );
			return;
		}

		$this->redirect_with_message( $post_id, 1000 );
	}

Top ↑

Changelog

Changelog
Version Description
5.13.3 Introduced.