WC_Order::status_transition
Handle the status transition.
Метод класса: WC_Order{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->status_transition();
Код WC_Order::status_transition() WC Order::status transition WC 10.4.3
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|false $note Order note. False will skip adding a note entirely.
* @type boolean $manual True if the order is manually changed.
* }
*/
do_action( 'woocommerce_order_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
// Add a status transition note unless `note` was explicitly set to false.
if ( false !== $status_transition['note'] ) {
if ( ! empty( $status_transition['from'] ) ) {
// Skip notes if the from status was a draft.
if ( ! in_array( $status_transition['from'], array( OrderStatus::DRAFT, OrderStatus::AUTO_DRAFT, OrderStatus::NEW, 'checkout-draft' ), true ) ) {
/* translators: 1: old order status 2: new order status */
$this->add_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'] ) ), $status_transition );
}
} 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 );
}
}
if ( ! empty( $status_transition['from'] ) ) {
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 );
/**
* Filter the valid order statuses for payment.
*
* @param array $valid_order_statuses Array of valid order statuses for payment.
* @param WC_Order $order Order object.
* @since 4.0.0
*/
$valid_order_statuses_for_payment = apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( OrderStatus::PENDING, OrderStatus::FAILED ), $this );
// Work out if this was for a payment, and trigger a payment_status hook instead.
if ( in_array( $status_transition['from'], $valid_order_statuses_for_payment, 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 );
}
}
} 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(), false, false, array( 'note_group' => OrderNoteGroup::ERROR ) );
}
}
}