WC_Order::status_transition()protectedWC 1.0

Handle the status transition.

Метод класса: WC_Order{}

Возвращает

null. Ничего (null).

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->status_transition();

Код WC_Order::status_transition() WC 8.7.0

protected function status_transition() {
	$status_transition = $this->status_transition;

	// Reset status transition variable.
	$this->status_transition = false;

	if ( $status_transition ) {
		try {
			/**
			 * Fires when order status is changed.
			 *
			 * @since 1.0.0
			 *
			 * @param int Order ID.
			 * @param WC_Order $order Order object.
			 * @param array $status_transition {
			 *      Status transition data.
			 *
			 *      @type string $from Order status from.
			 *      @type string $to Order status to
			 *      @type string $note Order note.
			 *      @type boolean $manual True if the order is manually changed.
			 * }
			 */
			do_action( 'woocommerce_order_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );

			if ( ! empty( $status_transition['from'] ) ) {
				/* translators: 1: old order status 2: new order status */
				$transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) );

				// Note the transition occurred.
				$this->add_status_transition_note( $transition_note, $status_transition );

				do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
				do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );

				// Work out if this was for a payment, and trigger a payment_status hook instead.
				if (
					in_array( $status_transition['from'], apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $this ), true )
					&& in_array( $status_transition['to'], wc_get_is_paid_statuses(), true )
				) {
					/**
					 * Fires when the order progresses from a pending payment status to a paid one.
					 *
					 * @since 3.9.0
					 * @param int Order ID
					 * @param WC_Order Order object
					 */
					do_action( 'woocommerce_order_payment_status_changed', $this->get_id(), $this );
				}
			} else {
				/* translators: %s: new order status */
				$transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['to'] ) );

				// Note the transition occurred.
				$this->add_status_transition_note( $transition_note, $status_transition );
			}
		} catch ( Exception $e ) {
			$logger = wc_get_logger();
			$logger->error(
				sprintf(
					'Status transition of order #%d errored!',
					$this->get_id()
				),
				array(
					'order' => $this,
					'error' => $e,
				)
			);
			$this->add_order_note( __( 'Error during status transition.', 'woocommerce' ) . ' ' . $e->getMessage() );
		}
	}
}