From 9f1c8a7a7608705dfd6ddff7a7651a86b45d86be Mon Sep 17 00:00:00 2001 From: Thomas Roberts <5656702+opr@users.noreply.github.com> Date: Tue, 2 Nov 2021 09:21:51 +0000 Subject: [PATCH] Graduate `__experimental_woocommerce_blocks_checkout_update_order_from_request` action to stable (#5015) * Deprecate __experimental_woocommerce_blocks_checkout_update_order_from_request * Update docs to show new action and remove deprecated one * Ensure correct args are passed to deprecated hook and update message * Amend deprecated tag and add version numbers * Remove incorrectly updated file from this PR --- bin/hook-docs/data/actions.json | 64 +++++++++---------- ...ature-flags-and-experimental-interfaces.md | 2 +- docs/examples/checkout-order-processed.md | 2 +- docs/extensibility/actions.md | 63 +++++++++--------- src/StoreApi/Routes/Checkout.php | 24 ++++++- 5 files changed, 85 insertions(+), 70 deletions(-) diff --git a/bin/hook-docs/data/actions.json b/bin/hook-docs/data/actions.json index dd2ec957bc0..ca6e7dbc86f 100644 --- a/bin/hook-docs/data/actions.json +++ b/bin/hook-docs/data/actions.json @@ -1,38 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/johnbillion/wp-hooks-generator/0.6.1/schema.json", "hooks": [ - { - "name": "__experimental_woocommerce_blocks_checkout_update_order_from_request", - "file": "StoreApi/Routes/Checkout.php", - "type": "action", - "doc": { - "description": "Fires when the Checkout Block/Store API updates an order's from the API request data.", - "long_description": "This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendRestAPI class to post custom data and then process it.", - "tags": [ - { - "name": "internal", - "content": "This Hook is experimental and may change or be removed." - }, - { - "name": "param", - "content": "Order object.", - "types": [ - "\\WC_Order" - ], - "variable": "$order" - }, - { - "name": "param", - "content": "Full details about the request.", - "types": [ - "\\WP_REST_Request" - ], - "variable": "$request" - } - ], - "long_description_html": "

This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendRestAPI class to post custom data and then process it.

" - } - }, { "name": "__experimental_woocommerce_blocks_checkout_update_order_meta", "file": "StoreApi/Routes/Checkout.php", @@ -144,7 +112,7 @@ }, { "name": "woocommerce_blocks_cart_enqueue_data", - "file": "BlockTypes/Cart.php", + "file": "BlockTypes/MiniCart.php", "type": "action", "doc": { "description": "Fires after cart block data is registered.", @@ -155,7 +123,7 @@ }, { "name": "woocommerce_blocks_cart_enqueue_data", - "file": "BlockTypes/MiniCart.php", + "file": "BlockTypes/Cart.php", "type": "action", "doc": { "description": "Fires after cart block data is registered.", @@ -204,6 +172,34 @@ "long_description_html": "

This hook informs extensions that $order has completed processing and is ready for payment.

This is similar to existing core hook woocommerce_checkout_order_processed. We're using a new action:

" } }, + { + "name": "woocommerce_blocks_checkout_update_order_from_request", + "file": "StoreApi/Routes/Checkout.php", + "type": "action", + "doc": { + "description": "Fires when the Checkout Block/Store API updates an order's from the API request data.", + "long_description": "This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendRestAPI class to post custom data and then process it.", + "tags": [ + { + "name": "param", + "content": "Order object.", + "types": [ + "\\WC_Order" + ], + "variable": "$order" + }, + { + "name": "param", + "content": "Full details about the request.", + "types": [ + "\\WP_REST_Request" + ], + "variable": "$request" + } + ], + "long_description_html": "

This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendRestAPI class to post custom data and then process it.

" + } + }, { "name": "woocommerce_blocks_enqueue_cart_block_scripts_after", "file": "BlockTypes/Cart.php", diff --git a/docs/blocks/feature-flags-and-experimental-interfaces.md b/docs/blocks/feature-flags-and-experimental-interfaces.md index 598fd458d51..22d5876b1ee 100644 --- a/docs/blocks/feature-flags-and-experimental-interfaces.md +++ b/docs/blocks/feature-flags-and-experimental-interfaces.md @@ -85,7 +85,7 @@ We also have individual features or code blocks behind a feature flag, this is a - `__experimental_woocommerce_blocks_payment_gateway_features_list` hook that allows modification of the features supported by PayPal Standard. ([experimental hook](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/4cedb65367be0d1c4c1f9dd9c016e3b1325cf92e/src/Payments/Integrations/PayPal.php#L86)). - `__experimental_woocommerce_blocks_checkout_update_order_meta` hook when the draft order has been created or updated from the cart and is now ready for extensions to modify the metadata ([experimental hook](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3686/files#diff-af2c90fa556cc086b780c8fad99b68373d87fd6007e6e2ff1b4c68ebe9ccb551R377-R393)). -- `__experimental_woocommerce_blocks_checkout_update_order_from_request` hook gives extensions the chance to update orders based on the data in the request ([experimental hook](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/d469a45d572f2c52d7917707c492dfb905ddfac0/src/StoreApi/Routes/Checkout.php#L466-L477)). +- **Deprecated** - `__experimental_woocommerce_blocks_checkout_update_order_from_request` hook gives extensions the chance to update orders based on the data in the request ([deprecated experimental hook](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/d469a45d572f2c52d7917707c492dfb905ddfac0/src/StoreApi/Routes/Checkout.php#L466-L477)). [Deprecated in PR 5015](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5015). - **Deprecated** - `__experimental_woocommerce_blocks_checkout_order_processed` hook when order has completed processing and is ready for payment ([deprecated experimental hook](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/accd1bbf402e043b9fc322f118ab614ba7437c92/src/StoreApi/Routes/Checkout.php#L237)). [Deprecated in PR 5014](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/5014). - `__experimental_woocommerce_blocks_add_data_attributes_to_namespace` hook that allows 3PD to add a namespace of blocks to receive block attributes as `data-` attributes ([experimental property](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/4a1ee97eb97011458174e93e44a9b7ad2f10ca36/src/BlockTypesController.php#L88)). - `__experimental_woocommerce_blocks_add_data_attributes_to_block` hook that allows 3PD to add a block to recieve block attributes as `data-` attributes ([experimental property](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/4a1ee97eb97011458174e93e44a9b7ad2f10ca36/src/BlockTypesController.php#L97)). diff --git a/docs/examples/checkout-order-processed.md b/docs/examples/checkout-order-processed.md index b3260a288b2..fd2bbdfdc74 100644 --- a/docs/examples/checkout-order-processed.md +++ b/docs/examples/checkout-order-processed.md @@ -5,5 +5,5 @@ function my_function_callback( $order ) { $order->save(); } -add_action( 'woocommerce_blocks_checkout_order_processed', 'my_function_callback', 10 ); +add_action( '__experimental_woocommerce_blocks_checkout_order_processed', 'my_function_callback', 10 ); ``` diff --git a/docs/extensibility/actions.md b/docs/extensibility/actions.md index 60d706e0659..7552105e0b9 100644 --- a/docs/extensibility/actions.md +++ b/docs/extensibility/actions.md @@ -7,7 +7,6 @@ ## Table of Contents - - [__experimental_woocommerce_blocks_checkout_update_order_from_request](#__experimental_woocommerce_blocks_checkout_update_order_from_request) - [__experimental_woocommerce_blocks_checkout_update_order_meta](#__experimental_woocommerce_blocks_checkout_update_order_meta) - [woocommerce_add_to_cart](#woocommerce_add_to_cart) - [woocommerce_applied_coupon](#woocommerce_applied_coupon) @@ -15,6 +14,7 @@ - [woocommerce_blocks_cart_enqueue_data](#woocommerce_blocks_cart_enqueue_data-1) - [woocommerce_blocks_checkout_enqueue_data](#woocommerce_blocks_checkout_enqueue_data) - [woocommerce_blocks_checkout_order_processed](#woocommerce_blocks_checkout_order_processed) + - [woocommerce_blocks_checkout_update_order_from_request](#woocommerce_blocks_checkout_update_order_from_request) - [woocommerce_blocks_enqueue_cart_block_scripts_after](#woocommerce_blocks_enqueue_cart_block_scripts_after) - [woocommerce_blocks_enqueue_cart_block_scripts_before](#woocommerce_blocks_enqueue_cart_block_scripts_before) - [woocommerce_blocks_enqueue_checkout_block_scripts_after](#woocommerce_blocks_enqueue_checkout_block_scripts_after) @@ -30,36 +30,6 @@ --- -## __experimental_woocommerce_blocks_checkout_update_order_from_request - - -Fires when the Checkout Block/Store API updates an order's from the API request data. - -```php -do_action( '__experimental_woocommerce_blocks_checkout_update_order_from_request', \WC_Order $order, \WP_REST_Request $request ) -``` - - -**Note: This Hook is experimental and may change or be removed.** - -### Description - -

This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendRestAPI class to post custom data and then process it.

- -### Parameters - -| Argument | Type | Description | -| -------- | ---- | ----------- | -| $order | \WC_Order | Order object. | -| $request | \WP_REST_Request | Full details about the request. | - -### Source - - -File: [StoreApi/Routes/Checkout.php](../src/StoreApi/Routes/Checkout.php) - ---- - ## __experimental_woocommerce_blocks_checkout_update_order_meta @@ -159,7 +129,7 @@ do_action( 'woocommerce_blocks_cart_enqueue_data' ) ### Source -File: [BlockTypes/Cart.php](../src/BlockTypes/Cart.php) +File: [BlockTypes/MiniCart.php](../src/BlockTypes/MiniCart.php) --- @@ -175,7 +145,7 @@ do_action( 'woocommerce_blocks_cart_enqueue_data' ) ### Source -File: [BlockTypes/MiniCart.php](../src/BlockTypes/MiniCart.php) +File: [BlockTypes/Cart.php](../src/BlockTypes/Cart.php) --- @@ -235,6 +205,33 @@ add_action( 'woocommerce_blocks_checkout_order_processed', 'my_function_callback ### Source +File: [StoreApi/Routes/Checkout.php](../src/StoreApi/Routes/Checkout.php) + +--- + +## woocommerce_blocks_checkout_update_order_from_request + + +Fires when the Checkout Block/Store API updates an order's from the API request data. + +```php +do_action( 'woocommerce_blocks_checkout_update_order_from_request', \WC_Order $order, \WP_REST_Request $request ) +``` + +### Description + +

This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendRestAPI class to post custom data and then process it.

+ +### Parameters + +| Argument | Type | Description | +| -------- | ---- | ----------- | +| $order | \WC_Order | Order object. | +| $request | \WP_REST_Request | Full details about the request. | + +### Source + + File: [StoreApi/Routes/Checkout.php](../src/StoreApi/Routes/Checkout.php) --- diff --git a/src/StoreApi/Routes/Checkout.php b/src/StoreApi/Routes/Checkout.php index eb214a93f07..9e5bada7cb8 100644 --- a/src/StoreApi/Routes/Checkout.php +++ b/src/StoreApi/Routes/Checkout.php @@ -499,8 +499,30 @@ private function update_order_from_request( \WP_REST_Request $request ) { * * @param \WC_Order $order Order object. * @param \WP_REST_Request $request Full details about the request. + * + * @deprecated 6.3.0 Use woocommerce_blocks_checkout_update_order_from_request instead. + */ + do_action_deprecated( + '__experimental_woocommerce_blocks_checkout_update_order_from_request', + array( + $this->order, + $request, + ), + '6.3.0', + 'woocommerce_blocks_checkout_update_order_from_request', + 'This action was deprecated in WooCommerce Blocks version 6.3.0. Please use woocommerce_blocks_checkout_update_order_from_request instead.' + ); + + /** + * Fires when the Checkout Block/Store API updates an order's from the API request data. + * + * This hook gives extensions the chance to update orders based on the data in the request. This can be used in + * conjunction with the ExtendRestAPI class to post custom data and then process it. + * + * @param \WC_Order $order Order object. + * @param \WP_REST_Request $request Full details about the request. */ - do_action( '__experimental_woocommerce_blocks_checkout_update_order_from_request', $this->order, $request ); + do_action( 'woocommerce_blocks_checkout_update_order_from_request', $this->order, $request ); $this->order->save(); }