diff --git a/src/Controllers/Version3/class-wc-rest-crud-controller.php b/src/Controllers/Version3/class-wc-rest-crud-controller.php index 1c66e9bbd20..76447c2e9fc 100644 --- a/src/Controllers/Version3/class-wc-rest-crud-controller.php +++ b/src/Controllers/Version3/class-wc-rest-crud-controller.php @@ -196,6 +196,15 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller { try { $this->update_additional_fields_for_object( $object, $request ); + + /** + * Fires after a single object is created or updated via the REST API. + * + * @param WC_Data $object Inserted object. + * @param WP_REST_Request $request Request object. + * @param boolean $creating True when creating object, false when updating. + */ + do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, true ); } catch ( WC_Data_Exception $e ) { $object->delete(); return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); @@ -204,15 +213,6 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } - /** - * Fires after a single object is created or updated via the REST API. - * - * @param WC_Data $object Inserted object. - * @param WP_REST_Request $request Request object. - * @param boolean $creating True when creating object, false when updating. - */ - do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, true ); - $request->set_param( 'context', 'edit' ); $response = $this->prepare_object_for_response( $object, $request ); $response = rest_ensure_response( $response ); @@ -243,21 +243,21 @@ abstract class WC_REST_CRUD_Controller extends WC_REST_Posts_Controller { try { $this->update_additional_fields_for_object( $object, $request ); + + /** + * Fires after a single object is created or updated via the REST API. + * + * @param WC_Data $object Inserted object. + * @param WP_REST_Request $request Request object. + * @param boolean $creating True when creating object, false when updating. + */ + do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, false ); } catch ( WC_Data_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), $e->getErrorData() ); } catch ( WC_REST_Exception $e ) { return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); } - /** - * Fires after a single object is created or updated via the REST API. - * - * @param WC_Data $object Inserted object. - * @param WP_REST_Request $request Request object. - * @param boolean $creating True when creating object, false when updating. - */ - do_action( "woocommerce_rest_insert_{$this->post_type}_object", $object, $request, false ); - $request->set_param( 'context', 'edit' ); $response = $this->prepare_object_for_response( $object, $request ); return rest_ensure_response( $response );