Introduce woocommerce_order_payment_status_changed action and logic around it when an order progresess from a pending payment to a paid status, in prep for Order status work.

This commit is contained in:
Gerhard 2019-12-03 16:20:24 +02:00
parent fd10af0669
commit 1f678767a9
1 changed files with 15 additions and 0 deletions

View File

@ -371,6 +371,21 @@ class WC_Order extends WC_Abstract_Order {
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' ) ), 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'] ) );