# Add a new inner block containing a custom field to the WooCommerce Checkout Block
This document describes how a developer can insert an input field into the Checkout block and have its value passed to the Store API so it's available when processing the checkout.
## Overview
Developers can extend the Checkout block to add new inner blocks and process additional data through the checkout POST request. This involves leveraging the extensibility interfaces provided by Gutenberg and WooCommerce Blocks. This is demonstrated in more detail in our tutorial: [Tutorial: Extending the WooCommerce Checkout Block
Refer to [this tutorial](https://developer.woo.com/2023/08/07/extending-the-woocommerce-checkout-block-to-add-custom-shipping-options/) for an example of adding a custom shipping option to the checkout block.
- The [lock attribute](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-templates/#individual-block-locking) is an object that controls whether the block can be removed or moved. By default, the lock attribute is set to allow the block to be removed and moved. However, by modifying the lock attribute, you can “force” the block to be non-removable. For example, you can set both remove and move properties to false in order to prevent the block from being removed or moved.
- The [parent attribute](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/#parent) specifies the parent block that this block should be nested within it. It determines where the block will render. In our example, the block is a child of the `woocommerce/checkout-shipping-methods-block`. This means that your block will be rendered within the `woocommerce/checkout-shipping-methods-block`. If the shipping methods block is not required, your block will not be rendered.
### 3. Setting custom checkout data
We can set the added field data to send it to the `wc/store/checkout` endpoint when processing orders using the function `setExtensionData`:
```JavaScript
setExtensionData(
'namespace-of-your-block',
'key-of-your-data',
value
);
```
#### Parameters
- namespace `string` - The namespace of your block.
- key `string` - The key of your data.
- value `any` - The value of your data.
#### How it works
1.`setExtensionData` is passed to inner blocks via props.
2. It updates the `extensionData` key of the `wc/store/checkout` data store.
3. This key is passed as part of the request body when POSTing to the checkout endpoint.
To process the added field data, we'll need extend the Store API to tell it to expect additional data. See more details in the [Exposing your data in the Store API](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/rest-api/extend-rest-api-add-data.md)
#### Code Example
We will use the following PHP files in our example:
- The `custom-inner-block-blocks-integration.php` file: Enqueue scripts, styles, and data on the frontend when the Checkout blocks is being used. See more details in the [IntegrationInterface](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/checkout-block/integration-interface.md) documentation.
```php
use Automattic\WooCommerce\Blocks\Integrations\IntegrationInterface;
/**
* Class for integrating with WooCommerce Blocks
*/
class Custom_Inner_Block_Blocks_Integration implements IntegrationInterface {
/**
* The name of the integration.
*
*@return string
*/
public function get_name() {
return 'new-field-block';
}
/**
* When called invokes any initialization/setup for the integration.
*/
public function initialize() {
// ... Some code here: (e.g. init functions that registers scripts and styles, and other instructions)
}
// ... Other functions here
}
```
- The `custom-inner-block-extend-store-endpoint.php` file: extends the [Store API](https://github.com/woocommerce/woocommerce-blocks/tree/trunk/src/StoreApi) and adds hooks to save and display your new field block instructions. This doesn't save the data from the custom block anywhere by default, but you can add your own logic to save the data to the database.
```php
use Automattic\WooCommerce\Blocks\Package;
use Automattic\WooCommerce\Blocks\StoreApi\Schemas\CartSchema;
use Automattic\WooCommerce\Blocks\StoreApi\Schemas\CheckoutSchema;
* Register the new field block schema into the Checkout endpoint.
*
*@return array Registered schema.
*
*/
public static function extend_checkout_schema() {
return [
'Value_1' => [
'description' => 'A description of the field',
'type' => 'string', // ... type of the field, this should be a string
'context' => [ 'view', 'edit' ], // ... context of the field, this should be an array containing 'view' and 'edit'
'readonly' => true, // ... whether the field is readonly or not, this should be a boolean
'optional' => true, // ... whether the field is optional or not, this should be a boolean
],
// ... other values
];
}
}
```
- The `new-field-block.php` file: the main plugin file that loads the `custom-inner-block-blocks-integration.php` and `custom-inner-block-extend-store-endpoint.php` files.
Here is an example from our [tutorial](https://developer.woo.com/2023/08/07/extending-the-woocommerce-checkout-block-to-add-custom-shipping-options/) of how to get this custom field's data while processing the checkout. This example is from the `shipping-workshop-blocks-integration.php` file. The complete code can be found in this [GitHub repository](https://github.com/woocommerce/wceu23-shipping-workshop-final/blob/main/shipping-workshop-blocks-integration.php#L42-L83).
* We write a hook, using the `woocommerce_store_api_checkout_update_order_from_request` action
* that will update the order metadata with the shipping-workshop alternate shipping instruction.
*
* The documentation for this hook is at: https://github.com/woocommerce/woocommerce-blocks/blob/b73fbcacb68cabfafd7c3e7557cf962483451dc1/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_store_api_checkout_update_order_from_request
By following the steps above, you can add and process new field blocks in the WooCommerce checkout block. For complete implementation and additional examples, refer to the provided [tutorial](https://developer.woo.com/2023/08/07/extending-the-woocommerce-checkout-block-to-add-custom-shipping-options/) and the corresponding [GitHub repository](https://github.com/woocommerce/wceu23-shipping-workshop-final/).