diff --git a/plugins/woocommerce/changelog/fix-35018-untrash-order-hook b/plugins/woocommerce/changelog/fix-35018-untrash-order-hook new file mode 100644 index 00000000000..65546d1d723 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-35018-untrash-order-hook @@ -0,0 +1,4 @@ +Significance: patch +Type: tweak + +Introduces new hook `woocommerce_untrash_order` as a COT/HPOS analog to `untrash_post`. diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php index 7729691a62d..7d94b7025b2 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php @@ -1838,6 +1838,16 @@ FROM $order_meta_table return false; } + /** + * Fires before an order is restored from the trash. + * + * @since 7.2.0 + * + * @param int $order_id Order ID. + * @param string $previous_status The status of the order before it was trashed. + */ + do_action( 'woocommerce_untrash_order', $order->get_id(), $previous_status ); + $order->set_status( $previous_status ); $order->save(); @@ -1845,6 +1855,7 @@ FROM $order_meta_table if ( $previous_status === $order->get_status() ) { $order->delete_meta_data( '_wp_trash_meta_status' ); $order->delete_meta_data( '_wp_trash_meta_time' ); + return true; }