2022-06-09 15:52:19 +00:00
<!-- DO NOT UPDATE THIS DOC DIRECTLY -->
<!-- Use `npm run build:docs` to automatically build hook documentation -->
# Actions
## Table of Contents
2022-08-01 08:56:28 +00:00
- [woocommerce_add_to_cart ](#woocommerce_add_to_cart )
- [woocommerce_after_main_content ](#woocommerce_after_main_content )
- [woocommerce_after_shop_loop ](#woocommerce_after_shop_loop )
- [woocommerce_applied_coupon ](#woocommerce_applied_coupon )
- [woocommerce_archive_description ](#woocommerce_archive_description )
- [woocommerce_before_main_content ](#woocommerce_before_main_content )
- [woocommerce_before_shop_loop ](#woocommerce_before_shop_loop )
- [woocommerce_blocks_cart_enqueue_data ](#woocommerce_blocks_cart_enqueue_data )
- [woocommerce_blocks_checkout_enqueue_data ](#woocommerce_blocks_checkout_enqueue_data )
- [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 )
- [woocommerce_blocks_enqueue_checkout_block_scripts_before ](#woocommerce_blocks_enqueue_checkout_block_scripts_before )
- [woocommerce_blocks_{$this->registry_identifier}_registration ](#woocommerce_blocks_-this--registry_identifier-_registration )
- [woocommerce_check_cart_items ](#-woocommerce_check_cart_items )
- [woocommerce_created_customer ](#woocommerce_created_customer )
- [woocommerce_no_products_found ](#woocommerce_no_products_found )
- [woocommerce_register_post ](#woocommerce_register_post )
- [woocommerce_rest_checkout_process_payment_with_context ](#woocommerce_rest_checkout_process_payment_with_context )
- [woocommerce_shop_loop ](#woocommerce_shop_loop )
- [woocommerce_store_api_cart_errors ](#woocommerce_store_api_cart_errors )
- [woocommerce_store_api_cart_update_customer_from_request ](#woocommerce_store_api_cart_update_customer_from_request )
- [woocommerce_store_api_cart_update_order_from_request ](#woocommerce_store_api_cart_update_order_from_request )
- [woocommerce_store_api_checkout_order_processed ](#woocommerce_store_api_checkout_order_processed )
- [woocommerce_store_api_checkout_update_customer_from_request ](#woocommerce_store_api_checkout_update_customer_from_request )
- [woocommerce_store_api_checkout_update_order_from_request ](#woocommerce_store_api_checkout_update_order_from_request )
- [woocommerce_store_api_checkout_update_order_meta ](#woocommerce_store_api_checkout_update_order_meta )
- [woocommerce_store_api_validate_add_to_cart ](#woocommerce_store_api_validate_add_to_cart )
- [woocommerce_store_api_validate_cart_item ](#woocommerce_store_api_validate_cart_item )
2022-06-09 15:52:19 +00:00
---
## woocommerce_add_to_cart
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires when an item is added to the cart.
```php
do_action( 'woocommerce_add_to_cart', string $cart_id, integer $product_id, integer $request_quantity, integer $variation_id, array $variation, array $cart_item_data )
```
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
**Note: Matches action name in WooCommerce core.**
### Description
< p > This hook fires when an item is added to the cart. This is triggered from the Store API in this context, but WooCommerce core add to cart events trigger the same hook.< / p >
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $cart_id | string | ID of the item in the cart. |
| $product_id | integer | ID of the product added to the cart. |
| $request_quantity | integer | Quantity of the item added to the cart. |
| $variation_id | integer | Variation ID of the product added to the cart. |
| $variation | array | Array of variation data. |
| $cart_item_data | array | Array of other cart item data. |
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Utilities/CartController.php ](../../../../src/StoreApi/Utilities/CartController.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_after_main_content
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Hook: woocommerce_after_main_content
```php
do_action( 'woocommerce_after_main_content' )
```
### Description
< p > Called after rendering the main content for a product.< / p >
### See
2022-08-01 08:56:28 +00:00
- woocommerce_output_content_wrapper_end() - Outputs closing DIV for the content (priority 10)
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/ClassicTemplate.php ](../../../../src/BlockTypes/ClassicTemplate.php )
- [BlockTypes/ClassicTemplate.php ](../../../../src/BlockTypes/ClassicTemplate.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_after_shop_loop
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Hook: woocommerce_after_shop_loop.
```php
do_action( 'woocommerce_after_shop_loop' )
```
### See
2022-08-01 08:56:28 +00:00
- woocommerce_pagination() - Renders pagination (priority 10)
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/ClassicTemplate.php ](../../../../src/BlockTypes/ClassicTemplate.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_applied_coupon
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires after a coupon has been applied to the cart.
```php
do_action( 'woocommerce_applied_coupon', string $coupon_code )
```
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
**Note: Matches action name in WooCommerce core.**
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $coupon_code | string | The coupon code that was applied. |
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Utilities/CartController.php ](../../../../src/StoreApi/Utilities/CartController.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_archive_description
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Hook: woocommerce_archive_description.
```php
do_action( 'woocommerce_archive_description' )
```
### See
2022-08-01 08:56:28 +00:00
- woocommerce_taxonomy_archive_description() - Renders the taxonomy archive description (priority 10)
- woocommerce_product_archive_description() - Renders the product archive description (priority 10)
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/ClassicTemplate.php ](../../../../src/BlockTypes/ClassicTemplate.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_before_main_content
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Hook: woocommerce_before_main_content
```php
do_action( 'woocommerce_before_main_content' )
```
### Description
< p > Called before rendering the main content for a product.< / p >
### See
2022-08-01 08:56:28 +00:00
- woocommerce_output_content_wrapper() - Outputs opening DIV for the content (priority 10)
- woocommerce_breadcrumb() - Outputs breadcrumb trail to the current product (priority 20)
- WC_Structured_Data::generate_website_data() - Outputs schema markup (priority 30)
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/ClassicTemplate.php ](../../../../src/BlockTypes/ClassicTemplate.php )
- [BlockTypes/ClassicTemplate.php ](../../../../src/BlockTypes/ClassicTemplate.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_before_shop_loop
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Hook: woocommerce_before_shop_loop.
```php
do_action( 'woocommerce_before_shop_loop' )
```
### See
2022-08-01 08:56:28 +00:00
- woocommerce_output_all_notices() - Render error notices (priority 10)
- woocommerce_result_count() - Show number of results found (priority 20)
- woocommerce_catalog_ordering() - Show form to control sort order (priority 30)
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/ClassicTemplate.php ](../../../../src/BlockTypes/ClassicTemplate.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_blocks_cart_enqueue_data
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires after cart block data is registered.
```php
do_action( 'woocommerce_blocks_cart_enqueue_data' )
```
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/Cart.php ](../../../../src/BlockTypes/Cart.php )
- [BlockTypes/MiniCart.php ](../../../../src/BlockTypes/MiniCart.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_blocks_checkout_enqueue_data
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires after checkout block data is registered.
```php
do_action( 'woocommerce_blocks_checkout_enqueue_data' )
```
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/Checkout.php ](../../../../src/BlockTypes/Checkout.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_blocks_enqueue_cart_block_scripts_after
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires after cart block scripts are enqueued.
```php
do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_after' )
```
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/Cart.php ](../../../../src/BlockTypes/Cart.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_blocks_enqueue_cart_block_scripts_before
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires before cart block scripts are enqueued.
```php
do_action( 'woocommerce_blocks_enqueue_cart_block_scripts_before' )
```
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/Cart.php ](../../../../src/BlockTypes/Cart.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_blocks_enqueue_checkout_block_scripts_after
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires after checkout block scripts are enqueued.
```php
do_action( 'woocommerce_blocks_enqueue_checkout_block_scripts_after' )
```
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/Checkout.php ](../../../../src/BlockTypes/Checkout.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_blocks_enqueue_checkout_block_scripts_before
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires before checkout block scripts are enqueued.
```php
do_action( 'woocommerce_blocks_enqueue_checkout_block_scripts_before' )
```
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/Checkout.php ](../../../../src/BlockTypes/Checkout.php )
2022-06-09 15:52:19 +00:00
---
2022-08-01 08:56:28 +00:00
## woocommerce_blocks_{$this->registry_identifier}_registration
2022-06-09 15:52:19 +00:00
Fires when the IntegrationRegistry is initialized.
```php
do_action( 'woocommerce_blocks_{$this->registry_identifier}_registration', \Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry $this )
```
### Description
< p > Runs before integrations are initialized allowing new integration to be registered for use. This should be used as the primary hook for integrations to include their scripts, styles, and other code extending the blocks.< / p >
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $this | \Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry | Instance of the IntegrationRegistry class which exposes the IntegrationRegistry::register() method. |
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [Integrations/IntegrationRegistry.php ](../../../../src/Integrations/IntegrationRegistry.php )
2022-06-09 15:52:19 +00:00
---
## ~~woocommerce_check_cart_items~~
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires when cart items are being validated.
```php
do_action( 'woocommerce_check_cart_items' )
```
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
**Deprecated: This hook is deprecated and will be removed**
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
**Note: Matches action name in WooCommerce core.**
### Description
< p > Allow 3rd parties to validate cart items. This is a legacy hook from Woo core. This filter will be deprecated because it encourages usage of wc_add_notice. For the API we need to capture notices and convert to wp errors instead.< / p >
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Utilities/CartController.php ](../../../../src/StoreApi/Utilities/CartController.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_created_customer
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires after a customer account has been registered.
```php
do_action( 'woocommerce_created_customer', integer $customer_id, array $new_customer_data, string $password_generated )
```
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
**Note: Matches filter name in WooCommerce core.**
### Description
< p > This hook fires after customer accounts are created and passes the customer data.< / p >
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $customer_id | integer | New customer (user) ID. |
| $new_customer_data | array | Array of customer (user) data. |
| $password_generated | string | The generated password for the account. |
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Routes/V1/Checkout.php ](../../../../src/StoreApi/Routes/V1/Checkout.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_no_products_found
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Hook: woocommerce_no_products_found.
```php
do_action( 'woocommerce_no_products_found' )
```
### See
2022-08-01 08:56:28 +00:00
- wc_no_products_found() - Default no products found content (priority 10)
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/ClassicTemplate.php ](../../../../src/BlockTypes/ClassicTemplate.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_register_post
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires before a customer account is registered.
```php
do_action( 'woocommerce_register_post', string $username, string $user_email, \WP_Error $errors )
```
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
**Note: Matches filter name in WooCommerce core.**
### Description
< p > This hook fires before customer accounts are created and passes the form data (username, email) and an array of errors.< / p > < p > This could be used to add extra validation logic and append errors to the array.< / p >
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $username | string | Customer username. |
| $user_email | string | Customer email address. |
| $errors | \WP_Error | Error object. |
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Routes/V1/Checkout.php ](../../../../src/StoreApi/Routes/V1/Checkout.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_rest_checkout_process_payment_with_context
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Process payment with context.
```php
do_action_ref_array( 'woocommerce_rest_checkout_process_payment_with_context', [ \Automattic\WooCommerce\StoreApi\Payments\PaymentContext $context, \Automattic\WooCommerce\StoreApi\Payments\PaymentResult $payment_result ] )
```
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $context | \Automattic\WooCommerce\StoreApi\Payments\PaymentContext | Holds context for the payment, including order ID and payment method. |
| $payment_result | \Automattic\WooCommerce\StoreApi\Payments\PaymentResult | Result object for the transaction. |
2022-06-09 15:52:19 +00:00
### Exceptions
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
`\Exception` If there is an error taking payment, an \Exception object can be thrown with an error message.
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Routes/V1/Checkout.php ](../../../../src/StoreApi/Routes/V1/Checkout.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_shop_loop
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Hook: woocommerce_shop_loop.
```php
do_action( 'woocommerce_shop_loop' )
```
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [BlockTypes/ClassicTemplate.php ](../../../../src/BlockTypes/ClassicTemplate.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_store_api_cart_errors
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires an action to validate the cart.
```php
do_action( 'woocommerce_store_api_cart_errors', \WP_Error $errors, \WC_Cart $cart )
```
### Description
< p > Functions hooking into this should add custom errors using the provided WP_Error instance.< / p >
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $errors | \WP_Error | WP_Error object. |
| $cart | \WC_Cart | Cart object. |
2022-06-09 15:52:19 +00:00
### Example
2022-08-01 08:56:28 +00:00
# Validate Cart
2022-06-09 15:52:19 +00:00
```php
// The action callback function.
function my_function_callback( $errors, $cart ) {
// Validate the $cart object and add errors. For example, to create an error if the cart contains more than 10 items:
if ( $cart->get_cart_contents_count() > 10 ) {
$errors->add( 'my_error_code', 'Too many cart items!' );
}
}
add_action( 'woocommerce_store_api_cart_errors', 'my_function_callback', 10 );
```
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Utilities/CartController.php ](../../../../src/StoreApi/Utilities/CartController.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_store_api_cart_update_customer_from_request
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires when the Checkout Block/Store API updates a customer from the API request data.
```php
do_action( 'woocommerce_store_api_cart_update_customer_from_request', \WC_Customer $customer, \WP_REST_Request $request )
```
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $customer | \WC_Customer | Customer object. |
| $request | \WP_REST_Request | Full details about the request. |
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Routes/V1/CartUpdateCustomer.php ](../../../../src/StoreApi/Routes/V1/CartUpdateCustomer.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_store_api_cart_update_order_from_request
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires when the order is synced with cart data from a cart route.
```php
do_action( 'woocommerce_store_api_cart_update_order_from_request', \WC_Order $draft_order, \WC_Customer $customer, \WP_REST_Request $request )
```
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $draft_order | \WC_Order | Order object. |
| $customer | \WC_Customer | Customer object. |
| $request | \WP_REST_Request | Full details about the request. |
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Routes/V1/AbstractCartRoute.php ](../../../../src/StoreApi/Routes/V1/AbstractCartRoute.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_store_api_checkout_order_processed
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires before an order is processed by the Checkout Block/Store API.
```php
do_action( 'woocommerce_store_api_checkout_order_processed', \WC_Order $order )
```
### Description
< p > This hook informs extensions that $order has completed processing and is ready for payment.< / p > < p > This is similar to existing core hook woocommerce_checkout_order_processed. We're using a new action:< / p > < ul > < li > To keep the interface focused (only pass $order, not passing request data).< / li > < li > This also explicitly indicates these orders are from checkout block/StoreAPI.< / li > < / ul >
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $order | \WC_Order | Order object. |
2022-06-09 15:52:19 +00:00
### Example
2022-08-01 08:56:28 +00:00
# Checkout Order Processed
2022-06-09 15:52:19 +00:00
```php
// The action callback function.
function my_function_callback( $order ) {
// Do something with the $order object.
$order->save();
}
add_action( 'woocommerce_blocks_checkout_order_processed', 'my_function_callback', 10 );
```
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
### See
2022-08-01 08:56:28 +00:00
- https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3238
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Routes/V1/Checkout.php ](../../../../src/StoreApi/Routes/V1/Checkout.php )
2022-08-01 08:56:28 +00:00
---
## woocommerce_store_api_checkout_update_customer_from_request
Fires when the Checkout Block/Store API updates a customer from the API request data.
```php
do_action( 'woocommerce_store_api_checkout_update_customer_from_request', \WC_Customer $customer, \WP_REST_Request $request )
```
### Parameters
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $customer | \WC_Customer | Customer object. |
| $request | \WP_REST_Request | Full details about the request. |
### Source
2022-09-12 04:29:24 +00:00
- [StoreApi/Routes/V1/Checkout.php ](../../../../src/StoreApi/Routes/V1/Checkout.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_store_api_checkout_update_order_from_request
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires when the Checkout Block/Store API updates an order's from the API request data.
```php
do_action( 'woocommerce_store_api_checkout_update_order_from_request', \WC_Order $order, \WP_REST_Request $request )
```
### Description
< p > This hook gives extensions the chance to update orders based on the data in the request. This can be used in conjunction with the ExtendSchema class to post custom data and then process it.< / p >
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $order | \WC_Order | Order object. |
| $request | \WP_REST_Request | Full details about the request. |
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Routes/V1/Checkout.php ](../../../../src/StoreApi/Routes/V1/Checkout.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_store_api_checkout_update_order_meta
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires when the Checkout Block/Store API updates an order's meta data.
```php
do_action( 'woocommerce_store_api_checkout_update_order_meta', \WC_Order $order )
```
### Description
< p > This hook gives extensions the chance to add or update meta data on the $order. Throwing an exception from a callback attached to this action will make the Checkout Block render in a warning state, effectively preventing checkout.< / p > < p > This is similar to existing core hook woocommerce_checkout_update_order_meta. We're using a new action:< / p > < ul > < li > To keep the interface focused (only pass $order, not passing request data).< / li > < li > This also explicitly indicates these orders are from checkout block/StoreAPI.< / li > < / ul >
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $order | \WC_Order | Order object. |
2022-06-09 15:52:19 +00:00
### See
2022-08-01 08:56:28 +00:00
- https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/3686
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Routes/V1/Checkout.php ](../../../../src/StoreApi/Routes/V1/Checkout.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_store_api_validate_add_to_cart
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fires during validation when adding an item to the cart via the Store API.
```php
do_action( 'woocommerce_store_api_validate_add_to_cart', \WC_Product $product, array $request )
```
### Description
< p > Fire action to validate add to cart. Functions hooking into this should throw an \Exception to prevent add to cart from happening.</ p >
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $product | \WC_Product | Product object being added to the cart. |
| $request | array | Add to cart request params including id, quantity, and variation attributes. |
2022-06-09 15:52:19 +00:00
### Source
2022-08-01 08:56:28 +00:00
2022-09-12 04:29:24 +00:00
- [StoreApi/Utilities/CartController.php ](../../../../src/StoreApi/Utilities/CartController.php )
2022-06-09 15:52:19 +00:00
---
## woocommerce_store_api_validate_cart_item
2022-08-01 08:56:28 +00:00
2022-06-09 15:52:19 +00:00
Fire action to validate add to cart. Functions hooking into this should throw an \Exception to prevent add to cart from occurring.
```php
do_action( 'woocommerce_store_api_validate_cart_item', \WC_Product $product, array $cart_item )
```
### Parameters
2022-08-01 08:56:28 +00:00
| Argument | Type | Description |
| -------- | ---- | ----------- |
| $product | \WC_Product | Product object being added to the cart. |
| $cart_item | array | Cart item array. |
2022-06-09 15:52:19 +00:00
### Source
2022-09-12 04:29:24 +00:00
- [StoreApi/Utilities/CartController.php ](../../../../src/StoreApi/Utilities/CartController.php )
2022-06-09 15:52:19 +00:00
2022-08-01 08:56:28 +00:00
---
2022-06-09 15:52:19 +00:00
<!-- FEEDBACK -->
---
[We're hiring! ](https://woocommerce.com/careers/ ) Come work with us!
2022-08-01 08:56:28 +00:00
🐞 Found a mistake, or have a suggestion? [Leave feedback about this document here. ](https://github.com/woocommerce/woocommerce-blocks/issues/new?assignees=&labels=type%3A+documentation&template=--doc-feedback.md&title=Feedback%20on%20./docs/third-party-developers/extensibility/hooks/actions.md )
2022-06-09 15:52:19 +00:00
<!-- /FEEDBACK -->
2022-08-01 08:56:28 +00:00