diff --git a/docs/building-a-woo-store/adding-a-custom-field-to-variable-products.md b/docs/building-a-woo-store/adding-a-custom-field-to-variable-products.md index 382c16cb4fb..e955b142144 100644 --- a/docs/building-a-woo-store/adding-a-custom-field-to-variable-products.md +++ b/docs/building-a-woo-store/adding-a-custom-field-to-variable-products.md @@ -1,6 +1,6 @@ --- post_title: How to add a custom field to simple and variable products -menu_title: Add custom fields to products +menu_title: Add Custom Fields to Products tags: how-to --- diff --git a/docs/cart-and-checkout-blocks/README.md b/docs/cart-and-checkout-blocks/README.md new file mode 100644 index 00000000000..693d6dbecea --- /dev/null +++ b/docs/cart-and-checkout-blocks/README.md @@ -0,0 +1,5 @@ +--- +category_title: Cart and Checkout Blocks +category_slug: cart-and-checkout-blocks +post_title: Cart and Checkout blocks - Extensibility +--- diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/additional-checkout-fields.md b/docs/cart-and-checkout-blocks/additional-checkout-fields.md similarity index 93% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/additional-checkout-fields.md rename to docs/cart-and-checkout-blocks/additional-checkout-fields.md index 9e80fa42ab5..c937347f82d 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/additional-checkout-fields.md +++ b/docs/cart-and-checkout-blocks/additional-checkout-fields.md @@ -1,55 +1,9 @@ --- -post_title: Cart and Checkout - Additional Checkout Fields +post_title: Cart and Checkout - Additional checkout fields +menu_title: Additional Checkout Fields tags: reference --- -# Additional Checkout Fields - -## Table of Contents - -- [Available field locations](#available-field-locations) - - [Contact information](#contact-information) - - [Address](#address) - - [Order information](#order-information) -- [Accessing values](#accessing-values) - - [Helper methods](#helper-methods) - - [Guest customers](#guest-customers) - - [Logged-in customers](#logged-in-customers) - - [Accessing all fields](#accessing-all-fields) - - [Accessing values directly](#accessing-values-directly) - - [Checkboxes values](#checkboxes-values) -- [Supported field types](#supported-field-types) -- [Using the API](#using-the-api) - - [Options](#options) - - [General options](#general-options) - - [Options for `text` fields](#options-for-text-fields) - - [Options for `select` fields](#options-for-select-fields) - - [Example of `options` value](#example-of-options-value) - - [Options for `checkbox` fields](#options-for-checkbox-fields) - - [Attributes](#attributes) -- [Usage examples](#usage-examples) - - [Rendering a text field](#rendering-a-text-field) - - [Rendering a checkbox field](#rendering-a-checkbox-field) - - [Rendering a select field](#rendering-a-select-field) - - [The select input before being focused](#the-select-input-before-being-focused) - - [The select input when focused](#the-select-input-when-focused) -- [Validation and sanitization](#validation-and-sanitization) - - [Sanitization](#sanitization) - - [Using the `woocommerce_sanitize_additional_field` filter](#using-the-woocommerce_sanitize_additional_field-filter) - - [Example of sanitization](#example-of-sanitization) - - [Validation](#validation) - - [Single field validation](#single-field-validation) - - [Using the `woocommerce_validate_additional_field` action](#using-the-woocommerce_validate_additional_field-action) - - [The `WP_Error` object](#the-wp_error-object) - - [Example of single-field validation](#example-of-single-field-validation) - - [Multiple field validation](#multiple-field-validation) - - [Using the `woocommerce_blocks_validate_location_{location}_fields` action](#using-the-woocommerce_blocks_validate_location_location_fields-action) - - [Example of location validation](#example-of-location-validation) -- [Backward compatibility](#backward-compatibility) - - [React to to saving fields](#react-to-to-saving-fields) - - [React to reading fields](#react-to-reading-fields) -- [A full example](#a-full-example) - A common use-case for developers and merchants is to add a new field to the Checkout form to collect additional data about a customer or their order. This document will outline the steps an extension should take to register some additional checkout fields. diff --git a/docs/cart-and-checkout-blocks/available-filters/README.md b/docs/cart-and-checkout-blocks/available-filters/README.md new file mode 100644 index 00000000000..6185107f41b --- /dev/null +++ b/docs/cart-and-checkout-blocks/available-filters/README.md @@ -0,0 +1,118 @@ +--- +category_title: Available Filters +category_slug: cart-and-checkout-available-filters +post_title: Cart and Checkout - Available Filters +--- + +This document lists the filters that are currently available to extensions and offers usage information for each one of them. Information on registering filters can be found on the [Checkout - Filter Registry](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/packages/checkout/filter-registry/README.md) page. + +## Cart Line Items filters + +The following [Cart Line Items filters](./cart-line-items.md) are available: + +- `cartItemClass` +- `cartItemPrice` +- `itemName` +- `saleBadgePriceFormat` +- `showRemoveItemLink` +- `subtotalPriceFormat` + +The following screenshot shows which parts the individual filters affect: + +![Cart Line Items](https://woocommerce.com/wp-content/uploads/2023/10/Screenshot-2023-10-26-at-13.12.33.png) + +## Order Summary Items filters + +The following [Order Summary Items filters](./order-summary-items.md) are available: + +- `cartItemClass` +- `cartItemPrice` +- `itemName` +- `subtotalPriceFormat` + +The following screenshot shows which parts the individual filters affect: + +![Order Summary Items](https://woocommerce.com/wp-content/uploads/2023/10/Screenshot-2023-10-26-at-16.29.45.png) + +## Totals Footer Item filter + +The following [Totals Footer Item filter](./totals-footer-item.md) is available: + +- `totalLabel` +- `totalValue` + +## Checkout and place order button filters + +The following [Checkout and place order button filters](./checkout-and-place-order-button.md) are available: + +- `proceedToCheckoutButtonLabel` +- `proceedToCheckoutButtonLink` +- `placeOrderButtonLabel` + +## Coupon filters + +The following [Coupon filters](./coupons.md) are available: + +- `coupons` +- `showApplyCouponNotice` +- `showRemoveCouponNotice` + +## Additional Cart and Checkout inner block types filter + +The following [Additional Cart and Checkout inner block types filter](./additional-cart-checkout-inner-block-types.md) is available: + +- `additionalCartCheckoutInnerBlockTypes` + +## Combined filters + +Filters can also be combined. The following example shows how to combine some of the available filters. + +```tsx +const { registerCheckoutFilters } = window.wc.blocksCheckout; + +const isOrderSummaryContext = ( args ) => args?.context === 'summary'; + +const modifyCartItemClass = ( defaultValue, extensions, args ) => { + if ( isOrderSummaryContext( args ) ) { + return 'my-custom-class'; + } + return defaultValue; +}; + +const modifyCartItemPrice = ( defaultValue, extensions, args ) => { + if ( isOrderSummaryContext( args ) ) { + return ' for all items'; + } + return defaultValue; +}; + +const modifyItemName = ( defaultValue, extensions, args ) => { + if ( isOrderSummaryContext( args ) ) { + return `${ defaultValue }`; + } + return defaultValue; +}; + +const modifySubtotalPriceFormat = ( defaultValue, extensions, args ) => { + if ( isOrderSummaryContext( args ) ) { + return ' per item'; + } + return defaultValue; +}; + +registerCheckoutFilters( 'example-extension', { + cartItemClass: modifyCartItemClass, + cartItemPrice: modifyCartItemPrice, + itemName: modifyItemName, + subtotalPriceFormat: modifySubtotalPriceFormat, +} ); +``` + +## Troubleshooting + +If you are logged in to the store as an administrator, you should be shown an error like this if your filter is not +working correctly. The error will also be shown in your console. + +![Troubleshooting](https://woocommerce.com/wp-content/uploads/2023/10/Screenshot-2023-10-30-at-10.52.53.png) + + diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/additional-cart-checkout-inner-block-types.md b/docs/cart-and-checkout-blocks/available-filters/additional-cart-checkout-inner-block-types.md similarity index 90% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/additional-cart-checkout-inner-block-types.md rename to docs/cart-and-checkout-blocks/available-filters/additional-cart-checkout-inner-block-types.md index 73c45ab6b69..e3b2eadf701 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/additional-cart-checkout-inner-block-types.md +++ b/docs/cart-and-checkout-blocks/available-filters/additional-cart-checkout-inner-block-types.md @@ -1,15 +1,12 @@ --- -post_title: Cart and Checkout - Inner Block Types +post_title: Cart and Checkout Filters - Inner block types menu_title: Inner Block Types -tags: reference, checkout-available-filters +tags: reference --- - -# Additional Cart and Checkout inner block types - The following Additional Cart and Checkout inner block types filter is available: -- [`additionalCartCheckoutInnerBlockTypes`](#additionalcartcheckoutinnerblocktypes) +- `additionalCartCheckoutInnerBlockTypes` ## `additionalCartCheckoutInnerBlockTypes` @@ -69,7 +66,7 @@ document.addEventListener( 'DOMContentLoaded', function () { To call this filter within the editor, wrap the filter registration in a `DOMContentLoaded` event listener and ensure the code runs in the admin panel. -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/cart-line-items.md b/docs/cart-and-checkout-blocks/available-filters/cart-line-items.md similarity index 88% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/cart-line-items.md rename to docs/cart-and-checkout-blocks/available-filters/cart-line-items.md index cc43d86555e..2a43c6940e6 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/cart-line-items.md +++ b/docs/cart-and-checkout-blocks/available-filters/cart-line-items.md @@ -1,26 +1,24 @@ --- -post_title: Cart and Checkout - Cart Line Items +post_title: Cart and Checkout Filters - Cart line items menu_title: Cart Line Items -tags: reference, checkout-available-filters +tags: reference --- -# Cart Line Items - The following Cart Line Items filters are available: -- [`cartItemClass`](#cartitemclass) -- [`cartItemPrice`](#cartitemprice) -- [`itemName`](#itemname) -- [`saleBadgePriceFormat`](#salebadgepriceformat) -- [`showRemoveItemLink`](#showremoveitemlink) -- [`subtotalPriceFormat`](#subtotalpriceformat) +- `cartItemClass` +- `cartItemPrice` +- `itemName` +- `saleBadgePriceFormat` +- `showRemoveItemLink` +- `subtotalPriceFormat` The following objects are shared between the filters: -- [Cart object](#cart-object) -- [Cart Item object](#cart-item-object) +- Cart object +- Cart Item object The following screenshot shows which parts the individual filters affect: @@ -37,8 +35,8 @@ The `cartItemClass` filter allows to change the cart item class. - _defaultValue_ `object` (default: `''`) - The default cart item class. - _extensions_ `object` (default: `{}`) - The extensions object. - _args_ `object` - The arguments object with the following keys: - - _cart_ `object` - The cart object from `wc/store/cart`, see [Cart object](#cart-object). - - _cartItem_ `object` - The cart item object from `wc/store/cart`, see [Cart Item object](#cart-item-object). + - _cart_ `object` - The cart object from `wc/store/cart`, see Cart object. + - _cartItem_ `object` - The cart item object from `wc/store/cart`, see Cart Item object. - _context_ `string` (allowed values: `cart` or `summary`) - The context of the item. ### Returns @@ -95,7 +93,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -112,17 +110,17 @@ The `cartItemPrice` filter allows to format the cart item price. ### Parameters -- _defaultValue_ `string` (default: ``) - The default cart item price. +- _defaultValue_ `string` (default: `<price/>`) - The default cart item price. - _extensions_ `object` (default: `{}`) - The extensions object. - _args_ `object` - The arguments object with the following keys: - - _cart_ `object` - The cart object from `wc/store/cart`, see [Cart object](#cart-object). - - _cartItem_ `object` - The cart item object from `wc/store/cart`, see [Cart Item object](#cart-item-object). + - _cart_ `object` - The cart object from `wc/store/cart`, see Cart object. + - _cartItem_ `object` - The cart item object from `wc/store/cart`, see Cart Item object. - _context_ `string` (allowed values: `cart` or `summary`) - The context of the item. -- _validation_ `boolean` - Checks if the return value contains the substring ``. +- _validation_ `boolean` - Checks if the return value contains the substring `<price/>`. ### Returns -- `string` - The modified format of the cart item price, which must contain the substring ``, or the original price format. +- `string` - The modified format of the cart item price, which must contain the substring `<price/>`, or the original price format. ### Code examples @@ -138,7 +136,7 @@ const modifyCartItemPrice = ( defaultValue, extensions, args, validation ) => { return defaultValue; } - return ' for all items'; + return '<price/> for all items'; }; registerCheckoutFilters( 'example-extension', { @@ -159,14 +157,14 @@ const modifyCartItemPrice = ( defaultValue, extensions, args, validation ) => { } if ( args?.cartItem?.name === 'Beanie with Logo' ) { - return ' to keep you β˜€οΈ'; + return '<price/> to keep you warm'; } if ( args?.cartItem?.name === 'Sunglasses' ) { - return ' to keep you ❄️'; + return '<price/> to keep you cool'; } - return ' for all items'; + return '<price/> for all items'; }; registerCheckoutFilters( 'example-extension', { @@ -174,7 +172,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -193,8 +191,8 @@ The `itemName` filter allows to change the cart item name. - _defaultValue_ `string` - The default cart item name. - _extensions_ `object` (default: `{}`) - The extensions object. - _args_ `object` - The arguments object with the following keys: - - _cart_ `object` - The cart object from `wc/store/cart`, see [Cart object](#cart-object). - - _cartItem_ `object` - The cart item object from `wc/store/cart`, see [Cart Item object](#cart-item-object). + - _cart_ `object` - The cart object from `wc/store/cart`, see Cart object. + - _cartItem_ `object` - The cart item object from `wc/store/cart`, see Cart Item object. - _context_ `string` (allowed values: `cart` or `summary`) - The context of the item. ### Returns @@ -251,7 +249,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -267,17 +265,17 @@ The `saleBadgePriceFormat` filter allows to format the cart item sale badge pric ### Parameters -- _defaultValue_ `string` (default: ``) - The default cart item sale badge price. +- _defaultValue_ `string` (default: `<price/>`) - The default cart item sale badge price. - _extensions_ `object` (default: `{}`) - The extensions object. - _args_ `object` - The arguments object with the following keys: - - _cart_ `object` - The cart object from `wc/store/cart`, see [Cart object](#cart-object). - - _cartItem_ `object` - The cart item object from `wc/store/cart`, see [Cart Item object](#cart-item-object). + - _cart_ `object` - The cart object from `wc/store/cart`, see Cart object. + - _cartItem_ `object` - The cart item object from `wc/store/cart`, see Cart Item object. - _context_ `string` (allowed values: `cart` or `summary`) - The context of the item. -- _validation_ `boolean` - Checks if the return value contains the substring ``. +- _validation_ `boolean` - Checks if the return value contains the substring `<price/>`. ### Returns -- `string` - The modified format of the cart item sale badge price, which must contain the substring ``, or the original price format. +- `string` - The modified format of the cart item sale badge price, which must contain the substring `<price/>`, or the original price format. ### Code examples @@ -296,7 +294,7 @@ const modifySaleBadgePriceFormat = ( return defaultValue; } - return ' per item'; + return '<price/> per item'; }; registerCheckoutFilters( 'example-extension', { @@ -322,14 +320,14 @@ const modifySaleBadgePriceFormat = ( } if ( args?.cartItem?.name === 'Beanie with Logo' ) { - return ' per item while keeping warm'; + return '<price/> per item while keeping warm'; } if ( args?.cartItem?.name === 'Sunglasses' ) { - return ' per item while looking cool'; + return '<price/> per item while looking cool'; } - return ' per item'; + return '<price/> per item'; }; registerCheckoutFilters( 'example-extension', { @@ -337,7 +335,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -357,8 +355,8 @@ The `showRemoveItemLink` is used to show or hide the cart item remove link. - _defaultValue_ (type: `boolean`, default: `true`) - The default value of the remove link. - _extensions_ `object` (default: `{}`) - The extensions object. - _args_ `object` - The arguments object with the following keys: - - _cart_ `object` - The cart object from `wc/store/cart`, see [Cart object](#cart-object). - - _cartItem_ `object` - The cart item object from `wc/store/cart`, see [Cart Item object](#cart-item-object). + - _cart_ `object` - The cart object from `wc/store/cart`, see Cart object. + - _cartItem_ `object` - The cart item object from `wc/store/cart`, see Cart Item object. - _context_ `string` (allowed values: `cart` or `summary`) - The context of the item. ### Returns @@ -415,7 +413,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -433,17 +431,17 @@ The `subtotalPriceFormat` filter allows to format the cart item subtotal price. ### Parameters -- _defaultValue_ `string` (default: ``) - The default cart item subtotal price. +- _defaultValue_ `string` (default: `<price/>`) - The default cart item subtotal price. - _extensions_ `object` (default: `{}`) - The extensions object. - _args_ `object` - The arguments object with the following keys: - - _cart_ `object` - The cart object from `wc/store/cart`, see [Cart object](#cart-object). - - _cartItem_ `object` - The cart item object from `wc/store/cart`, see [Cart Item object](#cart-item-object). + - _cart_ `object` - The cart object from `wc/store/cart`, see Cart object. + - _cartItem_ `object` - The cart item object from `wc/store/cart`, see Cart Item object. - _context_ `string` (allowed values: `cart` or `summary`) - The context of the item. -- _validation_ `boolean` - Checks if the return value contains the substring ``. +- _validation_ `boolean` - Checks if the return value contains the substring `<price/>`. ### Returns -- `string` - The modified format of the cart item subtotal price, which must contain the substring ``, or the original price format. +- `string` - The modified format of the cart item subtotal price, which must contain the substring `<price/>`, or the original price format. ### Code examples @@ -464,7 +462,7 @@ const modifySubtotalPriceFormat = ( return defaultValue; } - return ' per item'; + return '<price/> per item'; }; registerCheckoutFilters( 'example-extension', { @@ -490,14 +488,14 @@ const modifySubtotalPriceFormat = ( } if ( args?.cartItem?.name === 'Beanie with Logo' ) { - return ' per warm beanie'; + return '<price/> per warm beanie'; } if ( args?.cartItem?.name === 'Sunglasses' ) { - return ' per cool sunglasses'; + return '<price/> per cool sunglasses'; } - return ' per item'; + return '<price/> per item'; }; registerCheckoutFilters( 'example-extension', { @@ -505,7 +503,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -536,7 +534,7 @@ The Cart object of the filters above has the following keys: - _cartHasCalculatedShipping_ `boolean` - Whether the cart has calculated shipping. - _cartIsLoading_ `boolean` - Whether the cart is loading. - _cartItemErrors_ `array` - The cart item errors array. -- _cartItems_ `array` - The cart items array with cart item objects, see [Cart Item object](#cart-item-object). +- _cartItems_ `array` - The cart items array with cart item objects, see Cart Item object. - _cartItemsCount_ `number` - The cart items count. - _cartItemsWeight_ `number` - The cart items weight. - _cartNeedsPayment_ `boolean` - Whether the cart needs payment. diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/checkout-and-place-order-button.md b/docs/cart-and-checkout-blocks/available-filters/checkout-and-place-order-button.md similarity index 93% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/checkout-and-place-order-button.md rename to docs/cart-and-checkout-blocks/available-filters/checkout-and-place-order-button.md index 96a8a01daa5..c34b31dbbe6 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/checkout-and-place-order-button.md +++ b/docs/cart-and-checkout-blocks/available-filters/checkout-and-place-order-button.md @@ -1,21 +1,20 @@ --- -post_title: Cart and Checkout - Checkout and Place Order Button +post_title: Cart and Checkout Filters - Checkout and place order button menu_title: Checkout and Place Order Button -tags: reference, checkout-available-filters +tags: reference --- -# Checkout and place order button The following Checkout and place order button filters are available: -- [`proceedToCheckoutButtonLabel`](#proceedtocheckoutbuttonlabel) -- [`proceedToCheckoutButtonLink`](#proceedtocheckoutbuttonlink) -- [`placeOrderButtonLabel`](#placeorderbuttonlabel) +- `proceedToCheckoutButtonLabel` +- `proceedToCheckoutButtonLink` +- `placeOrderButtonLabel` The following objects are shared between the filters: -- [Cart object](#cart-object) -- [Cart Item object](#cart-item-object) +- Cart object +- Cart Item object ## `proceedToCheckoutButtonLabel` @@ -88,7 +87,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -107,7 +106,7 @@ The `proceedToCheckoutButtonLink` filter allows change the link of the "Proceed - _defaultValue_ `string` (default: `/checkout`) - The link of the "Proceed to checkout" button. - _extensions_ `object` (default: `{}`) - The extensions object. - _args_ `object` - The arguments object with the following keys: - - _cart_ `object` - The cart object from `wc/store/cart`, see [Cart object](../available-filters.md#cart-object). + - _cart_ `object` - The cart object from `wc/store/cart`, see [Cart object](./category/cart-and-checkout-blocks/available-filters/). ### Returns @@ -167,7 +166,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -204,7 +203,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/coupons.md b/docs/cart-and-checkout-blocks/available-filters/coupons.md similarity index 92% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/coupons.md rename to docs/cart-and-checkout-blocks/available-filters/coupons.md index bb20505a194..a1f2f8f69d1 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/coupons.md +++ b/docs/cart-and-checkout-blocks/available-filters/coupons.md @@ -1,18 +1,16 @@ --- post_title: Cart and Checkout Filters - Coupons menu_title: Coupons -tags: reference, checkout-available-filters +tags: reference --- -# Coupons - The following Coupon filters are available: -- [`coupons`](#coupons-1) -- [`showApplyCouponNotice`](#showapplycouponnotice) -- [`showRemoveCouponNotice`](#showremovecouponnotice) +- `coupons` +- `showApplyCouponNotice` +- `showRemoveCouponNotice` ## `coupons` @@ -66,7 +64,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -124,7 +122,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -182,7 +180,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/order-summary-items.md b/docs/cart-and-checkout-blocks/available-filters/order-summary-items.md similarity index 95% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/order-summary-items.md rename to docs/cart-and-checkout-blocks/available-filters/order-summary-items.md index 4f5188f2606..ce4134df03c 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/order-summary-items.md +++ b/docs/cart-and-checkout-blocks/available-filters/order-summary-items.md @@ -1,22 +1,21 @@ --- -post_title: Cart and Checkout Filters - Order Summary Items +post_title: Cart and Checkout Filters - Order summary items menu_title: Order Summary Items -tags: reference, checkout-available-filters +tags: reference --- -# Order Summary Items The following Order Summary Items filters are available: -- [`cartItemClass`](#cartitemclass) -- [`cartItemPrice`](#cartitemprice) -- [`itemName`](#itemname) -- [`subtotalPriceFormat`](#subtotalpriceformat) +- `cartItemClass` +- `cartItemPrice` +- `itemName` +- `subtotalPriceFormat` The following objects are shared between the filters: -- [Cart object](#cart-object) -- [Cart Item object](#cart-item-object) +- Cart object +- Cart Item object The following screenshot shows which parts the individual filters affect: @@ -91,7 +90,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -169,7 +168,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -246,7 +245,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -334,7 +333,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/totals-footer-item.md b/docs/cart-and-checkout-blocks/available-filters/totals-footer-item.md similarity index 95% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/totals-footer-item.md rename to docs/cart-and-checkout-blocks/available-filters/totals-footer-item.md index afd8d08b624..360c7627b80 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters/totals-footer-item.md +++ b/docs/cart-and-checkout-blocks/available-filters/totals-footer-item.md @@ -1,17 +1,15 @@ --- -post_title: Cart and Checkout - Totals Footer Item +post_title: Cart and Checkout Filters - Totals footer item menu_title: Totals Footer Item -tags: reference, checkout-available-filters +tags: reference --- -# Totals Footer Item - The following Totals Footer Item filter are available: -- [`totalLabel`](#totallabel) -- [`totalValue`](#totalvalue) +- `totalLabel` +- `totalValue` ## `totalLabel` @@ -48,7 +46,7 @@ registerCheckoutFilters( 'example-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots @@ -93,7 +91,7 @@ registerCheckoutFilters( 'my-extension', { } ); ``` -> πŸ’‘ Filters can be also combined. See [Combined filters](../available-filters.md#combined-filters) for an example. +> Filters can be also combined. See [Combined filters](./category/cart-and-checkout-blocks/available-filters/) for an example. ### Screenshots diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-slot-fills.md b/docs/cart-and-checkout-blocks/available-slot-fills.md similarity index 89% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-slot-fills.md rename to docs/cart-and-checkout-blocks/available-slot-fills.md index cde17679940..80effcba522 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-slot-fills.md +++ b/docs/cart-and-checkout-blocks/available-slot-fills.md @@ -1,27 +1,15 @@ --- -post_title: Cart and Checkout - Available Slots +post_title: Cart and Checkout - Available slots menu_title: Available Slots tags: reference --- -# Available Slots - -## Table of Contents - -- [ExperimentalOrderMeta](#experimentalordermeta) - - [Passed parameters](#passed-parameters) -- [ExperimentalOrderShippingPackages](#experimentalordershippingpackages) - - [Passed parameters](#passed-parameters-1) -- [ExperimentalOrderLocalPickupPackages](#experimentalorderlocalpickuppackages) - - [Passed parameters](#passed-parameters-2) -- [ExperimentalDiscountsMeta](#experimentaldiscountsmeta) - - [Passed parameters](#passed-parameters-3) This document presents the list of available Slots that you can use for adding your custom content (Fill). -If you want to add a new SlotFill component, check the [Checkout - Slot Fill document](../../../../packages/checkout/slot/README.md). To read more about Slot and Fill, check the [Slot and Fill document](./slot-fills.md). +If you want to add a new SlotFill component, check the [Checkout - Slot Fill document](https://github.com/woocommerce/woocommerce/blob/1675c63bba94c59703f57c7ef06e7deff8fd6bba/plugins/woocommerce-blocks/packages/checkout/slot/README.md). To read more about Slot and Fill, check the [Slot and Fill document](./cart-and-checkout-slot-and-fill/). -**Note About Naming:** Slots that are prefixed with `Experimental` are experimental and subject to change or remove. Once they graduate from the experimental stage, the naming would change and the `Experimental` prefix would be dropped. Check the [Feature Gating document](../../../internal-developers/blocks/feature-flags-and-experimental-interfaces.md) from more information. +**Note About Naming:** Slots that are prefixed with `Experimental` are experimental and subject to change or remove. Once they graduate from the experimental stage, the naming would change and the `Experimental` prefix would be dropped. Check the [Feature Gating document](https://github.com/woocommerce/woocommerce/blob/1675c63bba94c59703f57c7ef06e7deff8fd6bba/plugins/woocommerce-blocks/docs/internal-developers/blocks/feature-flags-and-experimental-interfaces.md) from more information. ## ExperimentalOrderMeta diff --git a/docs/cart-and-checkout-blocks/checkout-payment-methods/README.md b/docs/cart-and-checkout-blocks/checkout-payment-methods/README.md new file mode 100644 index 00000000000..1bed849220c --- /dev/null +++ b/docs/cart-and-checkout-blocks/checkout-payment-methods/README.md @@ -0,0 +1,8 @@ +--- +category_title: Payment Methods +category_slug: checkout-payment-methods +post_title: Checkout payment methods +--- + + + diff --git a/docs/cart-and-checkout-blocks/checkout-payment-methods/checkout-flow-and-events.md b/docs/cart-and-checkout-blocks/checkout-payment-methods/checkout-flow-and-events.md new file mode 100644 index 00000000000..cb85737967d --- /dev/null +++ b/docs/cart-and-checkout-blocks/checkout-payment-methods/checkout-flow-and-events.md @@ -0,0 +1,469 @@ +--- +post_title: Cart and Checkout - Checkout flow and events +menu_title: Checkout Flow and Events +tags: reference +--- + +This document gives an overview of the flow for the checkout in the WooCommerce checkout block, and some general architectural overviews. + +The architecture of the Checkout Block is derived from the following principles: + +- A single source of truth for data within the checkout flow. +- Provide a consistent interface for extension integrations (eg Payment methods). This interface protects the integrity of the checkout process and isolates extension logic from checkout logic. The checkout block handles _all_ communication with the server for processing the order. Extensions are able to react to and communicate with the checkout block via the provided interface. +- Checkout flow state is tracked by checkout status. +- Extensions are able to interact with the checkout flow via subscribing to emitted events. + +Here's a high level overview of the flow: + +![checkout flow diagram](https://user-images.githubusercontent.com/1628454/113739726-f8c9df00-96f7-11eb-80f1-78e25ccc88cb.png) + +## General Concepts + +### Tracking flow through status + +At any point in the checkout lifecycle, components should be able to accurately detect the state of the checkout flow. This includes things like: + +- Is something loading? What is loading? +- Is there an error? What is the error? +- is the checkout calculating totals? + +Using simple booleans can be fine in some cases, but in others it can lead to complicated conditionals and bug prone code (especially for logic behaviour that reacts to various flow state). + +To surface the flow state, the block uses statuses that are tracked in the various contexts. _As much as possible_ these statuses are set internally in reaction to various actions so there's no implementation needed in children components (components just have to _consume_ the status not set status). + +The following statuses exist in the Checkout. + +#### Checkout Data Store Status + +There are various statuses that are exposed on the Checkout data store via selectors. All the selectors are detailed below and in the [Checkout API docs](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/internal-developers/block-client-apis/checkout/checkout-api.md). + +You can use them in your component like so + +```jsx +const { useSelect } = window.wp.data; +const { CHECKOUT_STORE_KEY } = window.wc.wcBlocksData; + +const MyComponent = ( props ) => { + const isComplete = useSelect( ( select ) => + select( CHECKOUT_STORE_KEY ).isComplete() + ); + // do something with isComplete +}; +``` + +The following boolean flags available related to status are: + +**isIdle**: When the checkout status is `IDLE` this flag is true. Checkout will be this status after any change to checkout state after the block is loaded. It will also be this status when retrying a purchase is possible after processing happens with an error. + +**isBeforeProcessing**: When the checkout status is `BEFORE_PROCESSING` this flag is true. Checkout will be this status when the user submits checkout for processing. + +**isProcessing**: When the checkout status is `PROCESSING` this flag is true. Checkout will be this status when all the observers on the event emitted with the `BEFORE_PROCESSING` status are completed without error. It is during this status that the block will be sending a request to the server on the checkout endpoint for processing the order. **Note:** there are some checkout payment status changes that happen during this state as well (outlined in the `PaymentProvider` exposed statuses section). + +**isAfterProcessing**: When the checkout status is `AFTER_PROCESSING` this flag is true. Checkout will have this status after the block receives the response from the server side processing request. + +**isComplete**: When the checkout status is `COMPLETE` this flag is true. Checkout will have this status after all observers on the events emitted during the `AFTER_PROCESSING` status are completed successfully. When checkout is at this status, the shopper's browser will be redirected to the value of `redirectUrl` at that point (usually the `order-received` route). + +#### Special States + +The following are booleans exposed via the checkout provider that are independent from each other and checkout statuses but can be used in combination to react to various state in the checkout. + +**isCalculating:** This is true when the total is being re-calculated for the order. There are numerous things that might trigger a recalculation of the total: coupons being added or removed, shipping rates updated, shipping rate selected etc. This flag consolidates all activity that might be occurring (including requests to the server that potentially affect calculation of totals). So instead of having to check each of those individual states you can reliably just check if this boolean is true (calculating) or false (not calculating). + +**hasError:** This is true when anything in the checkout has created an error condition state. This might be validation errors, request errors, coupon application errors, payment processing errors etc. + +### `ShippingProvider` Exposed Statuses + +The shipping context provider exposes everything related to shipping in the checkout. Included in this are a set of error statuses that inform what error state the shipping context is in and the error state is affected by requests to the server on address changes, rate retrieval and selection. + +Currently the error status may be one of `NONE`, `INVALID_ADDRESS` or `UNKNOWN` (note, this may change in the future). + +The status is exposed on the `currentErrorStatus` object provided by the `useShippingDataContext` hook. This object has the following properties on it: + +- `isPristine` and `isValid`: Both of these booleans are connected to the same error status. When the status is `NONE` the values for these booleans will be `true`. It basically means there is no shipping error. +- `hasInvalidAddress`: When the address provided for shipping is invalid, this will be true. +- `hasError`: This is `true` when the error status for shipping is either `UNKNOWN` or `hasInvalidAddress`. + +### Payment Method Data Store Status + +The status of the payment lives in the payment data store. You can query the status with the following selectors: + +```jsx +const { select } = window.wp.data; +const { PAYMENT_STORE_KEY } = window.wc.wcBlocksData; + +const MyComponent = ( props ) => { + const isPaymentIdle = select( PAYMENT_STORE_KEY ).isPaymentIdle(); + const isExpressPaymentStarted = + select( PAYMENT_STORE_KEY ).isExpressPaymentStarted(); + const isPaymentProcessing = + select( PAYMENT_STORE_KEY ).isPaymentProcessing(); + const isPaymentReady = select( PAYMENT_STORE_KEY ).isPaymentReady(); + const hasPaymentError = select( PAYMENT_STORE_KEY ).hasPaymentError(); + + // do something with the boolean values +}; +``` + +The status here will help inform the current state of _client side_ processing for the payment and are updated via the store actions at different points throughout the checkout processing cycle. _Client side_ means the state of processing any payments by registered and active payment methods when the checkout form is submitted via those payment methods registered client side components. It's still possible that payment methods might have additional server side processing when the order is being processed but that is not reflected by these statuses (more in the [payment method integration doc](./payment-method-integration.md)). + +The possible _internal_ statuses that may be set are: + +- `IDLE`: This is the status when checkout is initialized and there are payment methods that are not doing anything. This status is also set whenever the checkout status is changed to `IDLE`. +- `EXPRESS_STARTED`: **Express Payment Methods Only** - This status is used when an express payment method has been triggered by the user clicking it's button. This flow happens before processing, usually in a modal window. +- `PROCESSING`: This status is set when the checkout status is `PROCESSING`, checkout `hasError` is false, checkout is not calculating, and the current payment status is not `FINISHED`. When this status is set, it will trigger the payment processing event emitter. +- `READY`: This status is set after all the observers hooked into the payment processing event have completed successfully. The `CheckoutProcessor` component uses this along with the checkout `PROCESSING` status to signal things are ready to send the order to the server with data for processing and to take payment +- `ERROR`: This status is set after an observer hooked into the payment processing event returns an error response. This in turn will end up causing the checkout `hasError` flag to be set to true. + +### Emitting Events + +Another tricky thing for extensibility, is providing opinionated, yet flexible interfaces for extensions to act and react to specific events in the flow. For stability, it's important that the core checkout flow _controls_ all communication to and from the server specific to checkout/order processing and leave extension specific requirements for the extension to handle. This allows for extensions to predictably interact with the checkout data and flow as needed without impacting other extensions hooking into it. + +One of the most reliable ways to implement this type of extensibility is via the usage of an events system. Thus the various context providers: + +- expose subscriber APIs for extensions to subscribe _observers_ to the events they want to react to. +- emit events at specific points of the checkout flow that in turn will feed data to the registered observers and, in some cases, react accordingly to the responses from observers. + +One _**very important rule**_ when it comes to observers registered to any event emitter in this system is that they _cannot_ update context state. Updating state local to a specific component is okay but not any context or global state. The reason for this is that the observer callbacks are run sequentially at a specific point and thus subsequent observers registered to the same event will not react to any change in global/context state in earlier executed observers. + +```jsx +const unsubscribe = emitter( myCallback ); +``` + +You could substitute in whatever emitter you are registering for the `emitter` function. So for example if you are registering for the `onCheckoutValidation` event emitter, you'd have something like: + +```jsx +const unsubscribe = onCheckoutValidation( myCallback ); +``` + +You can also indicate what priority you want your observer to execute at. Lower priority is run before higher priority, so you can affect when your observer will run in the stack of observers registered to an emitter. You indicate priority via an number on the second argument: + +```jsx +const unsubscribe = onCheckoutValidation( myCallback, 10 ); +``` + +In the examples, `myCallback`, is your subscriber function. The subscriber function could receive data from the event emitter (described in the emitter details below) and may be expected to return a response in a specific shape (also described in the specific emitter details). The subscriber function can be a `Promise` and when the event emitter cycles through the registered observers it will await for any registered Promise to resolve. + +Finally, the return value of the call to the emitter function is an unsubscribe function that can be used to unregister your observer. This is especially useful in a React component context where you need to make sure you unsubscribe the observer on component unmount. An example is usage in a `useEffect` hook: + +```jsx +const MyComponent = ( { onCheckoutValidation } ) => { + useEffect( () => { + const unsubscribe = onCheckoutValidation( () => true ); + return unsubscribe; + }, [ onCheckoutValidation ] ); + return null; +}; +``` + +**`Event Emitter Utilities`** + +There are a bunch of utility methods that can be used related to events. These are available in `assets/js/base/context/event-emit/utils.ts` and can be imported as follows: + +```jsx +import { + isSuccessResponse, + isErrorResponse, + isFailResponse, + noticeContexts, + responseTypes, + shouldRetry, +} from '@woocommerce/base-context'; +}; +``` + +The helper functions are described below: + +- `isSuccessResponse`, `isErrorResponse` and `isFailResponse`: These are helper functions that receive a value and report via boolean whether the object is a type of response expected. For event emitters that receive responses from registered observers, a `type` property on the returned object from the observer indicates what type of response it is and event emitters will react according to that type. So for instance if an observer returned `{ type: 'success' }` the emitter could feed that to `isSuccessResponse` and it would return `true`. You can see an example of this being implemented for the payment processing emitted event [here](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/34e17c3622637dbe8b02fac47b5c9b9ebf9e3596/assets/js/base/context/cart-checkout/payment-methods/payment-method-data-context.js#L281-L307). +- `noticeContexts`: This is an object containing properties referencing areas where notices can be targeted in the checkout. The object has the following properties: + - `PAYMENTS`: This is a reference to the notice area in the payment methods step. + - `EXPRESS_PAYMENTS`: This is a reference to the notice area in the express payment methods step. +- `responseTypes`: This is an object containing properties referencing the various response types that can be returned by observers for some event emitters. It makes it easier for autocompleting the types and avoiding typos due to human error. The types are `SUCCESS`, `FAIL`, `ERROR`. The values for these types also correspond to the [payment status types](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/34e17c3622637dbe8b02fac47b5c9b9ebf9e3596/src/Payments/PaymentResult.php#L21) from the [checkout endpoint response from the server](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/34e17c3622637dbe8b02fac47b5c9b9ebf9e3596/src/RestApi/StoreApi/Schemas/CheckoutSchema.php#L103-L113). +- `shouldRetry`: This is a function containing the logic whether the checkout flow should allow the user to retry the payment after a previous payment failed. It receives the `response` object and by default checks whether the `retry` property is true/undefined or false. Refer to the [`onCheckoutSuccess`](#oncheckoutsuccess) documentation for more details. + +Note: `noticeContexts` and `responseTypes` are exposed to payment methods via the `emitResponse` prop given to their component: + +```jsx +const MyPaymentMethodComponent = ( { emitResponse } ) => { + const { noticeContexts, responseTypes } = emitResponse; + // other logic for payment method... +}; +``` + +The following event emitters are available to extensions to register observers to: + +### `onCheckoutValidation` + +Observers registered to this event emitter will receive nothing as an argument. Also, all observers will be executed before the checkout handles the responses from the emitters. Observers registered to this emitter can return `true` if they have nothing to communicate back to checkout, `false` if they want checkout to go back to `IDLE` status state, or an object with any of the following properties: + +- `errorMessage`: This will be added as an error notice on the checkout context. +- `validationErrors`: This will be set as inline validation errors on checkout fields. If your observer wants to trigger validation errors it can use the following shape for the errors: + - This is an object where keys are the property names the validation error is for (that correspond to a checkout field, eg `country` or `coupon`) and values are the error message describing the validation problem. + +This event is emitted when the checkout status is `BEFORE_PROCESSING` (which happens at validation time, after the checkout form submission is triggered by the user - or Express Payment methods). + +If all observers return `true` for this event, then the checkout status will be changed to `PROCESSING`. + +This event emitter subscriber can be obtained via the checkout context using the `useCheckoutContext` hook or to payment method extensions as a prop on their registered component: + +_For internal development:_ + +```jsx +import { useCheckoutContext } from '@woocommerce/base-contexts'; +import { useEffect } from '@wordpress/element'; + +const Component = () => { + const { onCheckoutValidation } = useCheckoutContext(); + useEffect( () => { + const unsubscribe = onCheckoutValidation( () => true ); + return unsubscribe; + }, [ onCheckoutValidation ] ); + return null; +}; +``` + +_For registered payment method components:_ + +```jsx +const { useEffect } = window.wp.element; + +const PaymentMethodComponent = ( { eventRegistration } ) => { + const { onCheckoutValidation } = eventRegistration; + useEffect( () => { + const unsubscribe = onCheckoutValidation( () => true ); + return unsubscribe; + }, [ onCheckoutValidation ] ); +}; +``` + +### ~~`onPaymentProcessing`~~ + +This is now deprecated and replaced by the `onPaymentSetup` event emitter. + +### `onPaymentSetup` + +This event emitter was fired when the payment method context status is `PROCESSING` and that status is set when the checkout status is `PROCESSING`, checkout `hasError` is false, checkout is not calculating, and the current payment status is not `FINISHED`. + +This event emitter will execute through each registered observer (passing in nothing as an argument) _until_ an observer returns a non-truthy value at which point it will _abort_ further execution of registered observers. + +When a payment method returns a non-truthy value, if it returns a valid response type the event emitter will update various internal statuses according to the response. Here's the possible response types that will get handled by the emitter: + +#### Success + +A successful response should be given when the user's entered data is correct and the payment checks are successful. A response is considered successful if, at a minimum, it is an object with this shape: + +```js +const successResponse = { type: 'success' }; +``` + +When a success response is returned, the payment method context status will be changed to `SUCCESS`. In addition, including any of the additional properties will result in extra actions: + +- `paymentMethodData`: The contents of this object will be included as the value for `payment_data` when checkout sends a request to the checkout endpoint for processing the order. This is useful if a payment method does additional server side processing. +- `billingAddress`: This allows payment methods to update any billing data information in the checkout (typically used by Express payment methods) so it's included in the checkout processing request to the server. This data should be in the [shape outlined here](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/assets/js/settings/shared/default-fields.ts). +- `shippingAddress`: This allows payment methods to update any shipping data information for the order (typically used by Express payment methods) so it's included in the checkout processing request to the server. This data should be in the [shape outlined here](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/assets/js/settings/shared/default-fields.ts). + +If `billingAddress` or `shippingAddress` properties aren't in the response object, then the state for the data is left alone. + +#### Fail + +A fail response should be given when there is an error with the payment processing. A response is considered a fail response when it is an object with this shape: + +```js +const failResponse = { type: 'failure' }; +``` + +When a fail response is returned by an observer, the payment method context status will be changed to `FAIL`. In addition, including any of the following properties will result in extra actions: + +- `message`: The string provided here will be set as an error notice in the checkout. +- `messageContext`: If provided, this will target the given area for the error notice (this is where `noticeContexts` mentioned earlier come in to play). Otherwise the notice will be added to the `noticeContexts.PAYMENTS` area. +- `paymentMethodData`: (same as for success responses). +- `billingAddress`: (same as for success responses). + +#### Error + +An error response should be given when there is an error with the user input on the checkout form. A response is considered an error response when it is an object with this shape: + +```js +const errorResponse = { type: 'error' }; +``` + +When an error response is returned by an observer, the payment method context status will be changed to `ERROR`. In addition, including any of the following properties will result in extra actions: + +- `message`: The string provided here will be set as an error notice. +- `messageContext`: If provided, this will target the given area for the error notice (this is where `noticeContexts` mentioned earlier come in to play). Otherwise, the notice will be added to the `noticeContexts.PAYMENTS` area. +- `validationErrors`: This will be set as inline validation errors on checkout fields. If your observer wants to trigger validation errors it can use the following shape for the errors: + - This is an object where keys are the property names the validation error is for (that correspond to a checkout field, eg `country` or `coupon`) and values are the error message describing the validation problem. + +If the response object doesn't match any of the above conditions, then the fallback is to set the payment status as `SUCCESS`. + +When the payment status is set to `SUCCESS` and the checkout status is `PROCESSING`, the `CheckoutProcessor` component will trigger the request to the server for processing the order. + +This event emitter subscriber can be obtained via the checkout context using the `usePaymentEventsContext` hook or to payment method extensions as a prop on their registered component: + +_For internal development:_ + +```jsx +import { usePaymentEventsContext } from '@woocommerce/base-contexts'; +import { useEffect } from '@wordpress/element'; + +const Component = () => { + const { onPaymentSetup } = usePaymentEventsContext(); + useEffect( () => { + const unsubscribe = onPaymentSetup( () => true ); + return unsubscribe; + }, [ onPaymentSetup ] ); + return null; +}; +``` + +_For registered payment method components:_ + +```jsx +const { useEffect } = window.wp.element; + +const PaymentMethodComponent = ( { eventRegistration } ) => { + const { onPaymentSetup } = eventRegistration; + useEffect( () => { + const unsubscribe = onPaymentSetup( () => true ); + return unsubscribe; + }, [ onPaymentSetup ] ); +}; +``` + +### `onCheckoutSuccess` + +This event emitter is fired when the checkout status is `AFTER_PROCESSING` and the checkout `hasError` state is false. The `AFTER_PROCESSING` status is set by the `CheckoutProcessor` component after receiving a response from the server for the checkout processing request. + +Observers registered to this event emitter will receive the following object as an argument: + +```js +const onCheckoutProcessingData = { + redirectUrl, + orderId, + customerId, + orderNotes, + paymentResult, +}; +``` + +The properties are: + +- `redirectUrl`: This is a string that is the url the checkout will redirect to as returned by the processing on the server. +- `orderId`: Is the id of the current order being processed. +- `customerId`: Is the id for the customer making the purchase (that is attached to the order). +- `orderNotes`: This will be any custom note the customer left on the order. +- `paymentResult`: This is the value of [`payment_result` from the /checkout StoreApi response](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/34e17c3622637dbe8b02fac47b5c9b9ebf9e3596/src/RestApi/StoreApi/Schemas/CheckoutSchema.php#L103-L138). The data exposed on this object is (via the object properties): + - `paymentStatus`: Whatever the status is for the payment after it was processed server side. Will be one of `success`, `failure`, `pending`, `error`. + - `paymentDetails`: This will be an arbitrary object that contains any data the payment method processing server side sends back to the client in the checkout processing response. Payment methods are able to hook in on the processing server side and set this data for returning. + +This event emitter will invoke each registered observer until a response from any of the registered observers does not equal `true`. At that point any remaining non-invoked observers will be skipped and the response from the observer triggering the abort will be processed. + +This emitter will handle a `success` response type (`{ type: success }`) by setting the checkout status to `COMPLETE`. Along with that, if the response includes `redirectUrl` then the checkout will redirect to the given address. + +This emitter will also handle a `failure` response type or an `error` response type and if no valid type is detected it will treat it as an `error` response type. + +In all cases, if there are the following properties in the response, additional actions will happen: + +- `message`: This string will be added as an error notice. +- `messageContext`: If present, the notice will be configured to show in the designated notice area (otherwise it will just be a general notice for the checkout block). +- `retry`: If this is `true` or not defined, then the checkout status will be set to `IDLE`. This basically means that the error is recoverable (for example try a different payment method) and so checkout will be reset to `IDLE` for another attempt by the shopper. If this is `false`, then the checkout status is set to `COMPLETE` and the checkout will redirect to whatever is currently set as the `redirectUrl`. +- `redirectUrl`: If this is present, then the checkout will redirect to this url when the status is `COMPLETE`. + +If all observers return `true`, then the checkout status will just be set to `COMPLETE`. + +This event emitter subscriber can be obtained via the checkout context using the `useCheckoutContext` hook or to payment method extensions as a prop on their registered component: + +_For internal development:_ + +```jsx +import { useCheckoutContext } from '@woocommerce/base-contexts'; +import { useEffect } from '@wordpress/element'; + +const Component = () => { + const { onCheckoutSuccess } = useCheckoutContext(); + useEffect( () => { + const unsubscribe = onCheckoutSuccess( () => true ); + return unsubscribe; + }, [ onCheckoutSuccess ] ); + return null; +}; +``` + +_For registered payment method components:_ + +```jsx +const { useEffect } = window.wp.element; + +const PaymentMethodComponent = ( { eventRegistration } ) => { + const { onCheckoutSuccess } = eventRegistration; + useEffect( () => { + const unsubscribe = onCheckoutSuccess( () => true ); + return unsubscribe; + }, [ onCheckoutSuccess ] ); +}; +``` + +### `onCheckoutFail` + +This event emitter is fired when the checkout status is `AFTER_PROCESSING` and the checkout `hasError` state is `true`. The `AFTER_PROCESSING` status is set by the `CheckoutProcessor` component after receiving a response from the server for the checkout processing request. + +Observers registered to this emitter will receive the same data package as those registered to `onCheckoutSuccess`. + +The response from the first observer returning a value that does not `===` true will be handled similarly as the `onCheckoutSuccess` except it only handles when the type is `error` or `failure`. + +If all observers return `true`, then the checkout status will just be set to `IDLE` and a default error notice will be shown in the checkout context. + +This event emitter subscriber can be obtained via the checkout context using the `useCheckoutContext` hook or to payment method extensions as a prop on their registered component: + +_For internal development:_ + +```jsx +import { useCheckoutContext } from '@woocommerce/base-contexts'; +import { useEffect } from '@wordpress/element'; + +const Component = () => { + const { onCheckoutFail } = useCheckoutContext(); + useEffect( () => { + const unsubscribe = onCheckoutFail( () => true ); + return unsubscribe; + }, [ onCheckoutFail ] ); + return null; +}; +``` + +_For registered payment method components:_ + +```jsx +const { useEffect } = window.wp.element; + +const PaymentMethodComponent = ( { eventRegistration } ) => { + const { onCheckoutFail } = eventRegistration; + useEffect( () => { + const unsubscribe = onCheckoutFail( () => true ); + return unsubscribe; + }, [ onCheckoutFail ] ); +}; +``` + +### `onShippingRateSuccess` + +This event emitter is fired when shipping rates are not loading and the shipping data context error state is `NONE` and there are shipping rates available. + +This event emitter doesn't care about any registered observer response and will simply execute all registered observers passing them the current shipping rates retrieved from the server. + +### `onShippingRateFail` + +This event emitter is fired when shipping rates are not loading and the shipping data context error state is `UNKNOWN` or `INVALID_ADDRESS`. + +This event emitter doesn't care about any registered observer response and will simply execute all registered observers passing them the current error status in the context. + +### `onShippingRateSelectSuccess` + +This event emitter is fired when a shipping rate selection is not being persisted to the server and there are selected rates available and the current error status in the context is `NONE`. + +This event emitter doesn't care about any registered observer response and will simply execute all registered observers passing them the current selected rates. + +### `onShippingRateSelectFail` + +This event emitter is fired when a shipping rate selection is not being persisted to the server and the shipping data context error state is `UNKNOWN` or `INVALID_ADDRESS`. + +This event emitter doesn't care about any registered observer response and will simply execute all registered observers passing them the current error status in the context. diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/filtering-payment-methods.md b/docs/cart-and-checkout-blocks/checkout-payment-methods/filtering-payment-methods.md similarity index 87% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/filtering-payment-methods.md rename to docs/cart-and-checkout-blocks/checkout-payment-methods/filtering-payment-methods.md index b7e674bfac6..7c7ad390211 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/filtering-payment-methods.md +++ b/docs/cart-and-checkout-blocks/checkout-payment-methods/filtering-payment-methods.md @@ -1,30 +1,11 @@ --- post_title: Cart and Checkout - Filtering payment methods in the Checkout block menu_title: Filtering Payment Methods -tags: how-to, checkout-payment-methods +tags: how-to --- -# Filtering Payment Methods in the Checkout block - -## Table of Contents - -- [The problem](#the-problem) - - [The solution](#the-solution) - - [Importing](#importing) - - [Aliased import](#aliased-import) - - [`wc global`](#wc-global) - - [Signature](#signature) - - [Extension namespace collision](#extension-namespace-collision) - - [Usage example](#usage-example) - - [Callbacks registered for payment methods](#callbacks-registered-for-payment-methods) -- [Filtering payment methods using requirements](#filtering-payment-methods-using-requirements) - - [The problem](#the-problem-1) - - [The solution](#the-solution-1) - - [Basic usage](#basic-usage) - - [Putting it all together](#putting-it-all-together) - ## The problem You're an extension developer, and your extension is conditionally hiding payment gateways on the checkout step. You need to be able to hide payment gateways on the Checkout block using a front-end extensibility point. @@ -105,7 +86,8 @@ interface CanMakePaymentArgument { } ``` -If you need data that is not available in the parameter received by the callback you can consider [exposing your data in the Store API](../rest-api/extend-rest-api-add-data.md). +If you need data that is not available in the parameter received by the callback you can consider [exposing your data in the Store API](https://github.com/woocommerce/woocommerce/blob/1675c63bba94c59703f57c7ef06e7deff8fd6bba/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/extend-rest-api-add-data.md). + ## Filtering payment methods using requirements @@ -121,7 +103,7 @@ To allow the shopper to check out without entering payment details, but still re Using the `supports` configuration of payment methods it is possible to prevent other payment methods (such as credit card, PayPal etc.) from being used to check out, and only allow the one your extension has added to appear in the Checkout block. -For more information on how to register a payment method with WooCommerce Blocks, please refer to the [Payment method integration](../checkout-payment-methods/payment-method-integration.md) documentation. +For more information on how to register a payment method with WooCommerce Blocks, please refer to the [Payment method integration](./payment-method-integration.md) documentation. ### Basic usage diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/payment-method-integration.md b/docs/cart-and-checkout-blocks/checkout-payment-methods/payment-method-integration.md similarity index 95% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/payment-method-integration.md rename to docs/cart-and-checkout-blocks/checkout-payment-methods/payment-method-integration.md index e1b9a1524dd..602bcb7deaa 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/payment-method-integration.md +++ b/docs/cart-and-checkout-blocks/checkout-payment-methods/payment-method-integration.md @@ -1,37 +1,9 @@ --- post_title: Cart and Checkout - Payment method integration for the Checkout block menu_title: Payment Method Integration -tags: reference, checkout-payment-methods +tags: reference --- -# Payment Method Integration for the Checkout Block - -The checkout block has an API interface for payment methods to integrate that consists of both a server side and client side implementation. - -## Table of Contents - -- [Client Side integration](#client-side-integration) - - [Express payment methods - `registerExpressPaymentMethod( options )`](#express-payment-methods---registerexpresspaymentmethod-options-) - - [Aliased import](#registerexpresspaymentmethod-aliased-import) - - [`wc global`](#registerexpresspaymentmethod-on-the-wc-global) - - [The registration options](#the-registerexpresspaymentmethod-registration-options) - - [`name` (required)](#name-required) - - [`content` (required)](#content-required) - - [`edit` (required)](#edit-required) - - [`canMakePayment` (required)](#canmakepayment-required) - - [`paymentMethodId`](#paymentmethodid) - - [`supports:features`](#supportsfeatures) - - [Payment Methods - `registerPaymentMethod( options )`](#payment-methods---registerpaymentmethod-options-) - - [Aliased import](#registerpaymentmethod-aliased-import) - - [`wc global`](#registerpaymentmethod-on-the-wc-global) - - [The registration options](#the-registerpaymentmethod-registration-options) - - [Props Fed to Payment Method Nodes](#props-fed-to-payment-method-nodes) -- [Server Side Integration](#server-side-integration) - - [Processing Payment](#processing-payment) - - [Registering Assets](#registering-assets) - - [Hooking into the Checkout processing by the Store API](#hooking-into-the-checkout-processing-by-the-store-api) - - [Putting it all together](#putting-it-all-together) - ## Client Side integration The client side integration consists of an API for registering both _express_ payment methods (those that consist of a one-button payment process initiated by the shopper such as Stripe, ApplePay, or GooglePay), and payment methods such as _cheque_, PayPal Standard, or Stripe Credit Card. @@ -89,7 +61,7 @@ This should be a unique string (wise to try to pick something unique for your ga #### `content` (required) -This should be a React node that will output in the express payment method area when the block is rendered in the frontend. It will be cloned in the rendering process. When cloned, this React node will receive props passed in from the checkout payment method interface that will allow your component to interact with checkout data (more on [these props later](./payment-method-integration.md#props-fed-to-payment-method-nodes)). +This should be a React node that will output in the express payment method area when the block is rendered in the frontend. It will be cloned in the rendering process. When cloned, this React node will receive props passed in from the checkout payment method interface that will allow your component to interact with checkout data (more on [these props later](#props-fed-to-payment-method-nodes)). #### `edit` (required) @@ -165,7 +137,7 @@ The options you feed the configuration instance are the same as those for expres ### Props Fed to Payment Method Nodes -A big part of the payment method integration is the interface that is exposed for payment methods to use via props when the node provided is cloned and rendered on block mount. While all the props are listed below, you can find more details about what the props reference, their types etc via the [typedefs described in this file](../../../../assets/js/types/type-defs/payment-method-interface.ts). +A big part of the payment method integration is the interface that is exposed for payment methods to use via props when the node provided is cloned and rendered on block mount. While all the props are listed below, you can find more details about what the props reference, their types etc via the [typedefs described in this file](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/assets/js/types/type-defs/payment-method-interface.ts). | Property | Type | Description | Values | | ------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/dom-events.md b/docs/cart-and-checkout-blocks/dom-events.md similarity index 86% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/dom-events.md rename to docs/cart-and-checkout-blocks/dom-events.md index cacf6c7dda5..0930693cae2 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/dom-events.md +++ b/docs/cart-and-checkout-blocks/dom-events.md @@ -1,20 +1,9 @@ --- -post_title: Cart and Checkout - Dom Events -menu_title: Dom Events +post_title: Cart and Checkout - DOM events +menu_title: DOM Events tags: reference --- -# DOM Events - -## Table of Contents - -- [WooCommerce core events in WooCommerce Blocks](#woocommerce-core-events-in-woocommerce-blocks) -- [WooCommerce Blocks events](#woocommerce-blocks-events) - - [`wc-blocks_adding_to_cart`](#wc-blocks_adding_to_cart) - - [`wc-blocks_added_to_cart`](#wc-blocks_added_to_cart) - - [`detail` parameters:](#detail-parameters) - - [`wc-blocks_removed_from_cart`](#wc-blocks_removed_from_cart) - Some blocks need to react to certain events in order to display the most up to date data or behave in a certain way. That's the case of the Cart block, for example, that must listen to 'add to cart' events in order to update the cart contents; or the Mini-Cart block, that gets opened every time a product is added to the cart. ## WooCommerce core events in WooCommerce Blocks diff --git a/docs/cart-and-checkout-blocks/hooks/README.md b/docs/cart-and-checkout-blocks/hooks/README.md new file mode 100644 index 00000000000..f7c4034e554 --- /dev/null +++ b/docs/cart-and-checkout-blocks/hooks/README.md @@ -0,0 +1,8 @@ +--- +category_title: Hooks +category_slug: cart-and-checkout-hooks +post_title: Cart and Checkout - Hooks +--- + + + diff --git a/docs/cart-and-checkout-blocks/hooks/migrated-hooks.md b/docs/cart-and-checkout-blocks/hooks/migrated-hooks.md new file mode 100644 index 00000000000..fb25b947531 --- /dev/null +++ b/docs/cart-and-checkout-blocks/hooks/migrated-hooks.md @@ -0,0 +1,50 @@ +--- +post_title: Cart and Checkout - Legacy hooks +menu_title: Legacy Hooks +tags: reference +--- + +Below are the hooks that exist in WooCommerce core and that were brough over to WooCommerce Blocks. + +Please note that the actions and filters here run on the server side. The client-side blocks won't necessarily change based on a callback added to a server side hook. [Please see our documentation relating to APIs for manipulating the blocks on the client-side](./an-introduction-to-extensiblity-in-woocommerce-blocks/). + +## Legacy Filters + +- [loop_shop_per_page](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#loop_shop_per_page) +- [wc_session_expiration](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#wc_session_expiration) +- [woocommerce_add_cart_item](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_add_cart_item) +- [woocommerce_add_cart_item_data](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_add_cart_item_data) +- [woocommerce_add_to_cart_quantity](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_add_to_cart_quantity) +- [woocommerce_add_to_cart_sold_individually_quantity](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_add_to_cart_sold_individually_quantity) +- [woocommerce_add_to_cart_validation](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_add_to_cart_validation) +- [woocommerce_adjust_non_base_location_prices](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_adjust_non_base_location_prices) +- [woocommerce_apply_base_tax_for_local_pickup](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_apply_base_tax_for_local_pickup) +- [woocommerce_apply_individual_use_coupon](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_apply_individual_use_coupon) +- [woocommerce_apply_with_individual_use_coupon](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_apply_with_individual_use_coupon) +- [woocommerce_cart_contents_changed](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_cart_contents_changed) +- [woocommerce_cart_item_permalink](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_cart_item_permalink) +- [woocommerce_get_item_data](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_get_item_data) +- [woocommerce_loop_add_to_cart_args](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_loop_add_to_cart_args) +- [woocommerce_loop_add_to_cart_link](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_loop_add_to_cart_link) +- [woocommerce_new_customer_data](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_new_customer_data) +- [woocommerce_pay_order_product_has_enough_stock](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_pay_order_product_has_enough_stock) +- [woocommerce_pay_order_product_in_stock](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_pay_order_product_in_stock) +- [woocommerce_registration_errors](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_registration_errors) +- [woocommerce_shipping_package_name](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_shipping_package_name) +- [woocommerce_show_page_title](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_show_page_title) +- [woocommerce_single_product_image_thumbnail_html](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/filters.md#woocommerce_single_product_image_thumbnail_html) + +## Legacy Actions + +- [woocommerce_add_to_cart](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_add_to_cart) +- [woocommerce_after_main_content](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_after_main_content) +- [woocommerce_after_shop_loop](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_after_shop_loop) +- [woocommerce_applied_coupon](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_applied_coupon) +- [woocommerce_archive_description](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_archive_description) +- [woocommerce_before_main_content](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_before_main_content) +- [woocommerce_before_shop_loop](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_before_shop_loop) +- [woocommerce_check_cart_items](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_check_cart_items) +- [woocommerce_created_customer](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_created_customer) +- [woocommerce_no_products_found](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_no_products_found) +- [woocommerce_register_post](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_register_post) +- [woocommerce_shop_loop](https://github.com/woocommerce/woocommerce-blocks/blob/trunk/docs/third-party-developers/extensibility/hooks/actions.md#woocommerce_shop_loop) diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/how-checkout-processes-an-order.md b/docs/cart-and-checkout-blocks/how-checkout-processes-an-order.md similarity index 73% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/how-checkout-processes-an-order.md rename to docs/cart-and-checkout-blocks/how-checkout-processes-an-order.md index 4821e9908a6..69b6eb2f13a 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/how-checkout-processes-an-order.md +++ b/docs/cart-and-checkout-blocks/how-checkout-processes-an-order.md @@ -1,24 +1,22 @@ --- -post_title: Cart and Checkout - How the Checkout block processes an order -menu_title: Processing an order +post_title: Cart and Checkout - How the checkout block processes an order +menu_title: Processing an Order tags: reference --- -# How The Checkout Block Processes an Order - -This document will shed some light on the inner workings of the Checkout flow. More specifically, what happens after a user hits the β€œPlace Order” button. +This document will shed some light on the inner workings of the Checkout flow. More specifically, what happens after a user hits the "Place Order" button. ## Structure The following areas are associated with processing the checkout for a user. -### The Payment Registry [:file_folder:](https://href.li/?https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/blocks-registry/payment-methods/registry.ts#L1) +### The Payment Registry [(file)](https://href.li/?https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/blocks-registry/payment-methods/registry.ts#L1) The payment registry stores all the configuration information for each payment method. We can register a new payment method here with the `registerPaymentMethod` and `registerExpressPaymentMethod `functions, also available to other plugins. ### Data Stores -Data stores are used to keep track of data that is likely to change during a user’s session, such as the active payment method, whether the checkout has an error, etc. We split these data stores by areas of concern, so we have 2 data stores related to the checkout: `wc/store/checkout` [:file_folder:](https://href.li/?https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/index.ts#L1) and `wc/store/payment` [:file_folder:](https://href.li/?https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/payment-methods/index.ts#L1) . Data stores live in the `assets/js/data` folder. +Data stores are used to keep track of data that is likely to change during a user's session, such as the active payment method, whether the checkout has an error, etc. We split these data stores by areas of concern, so we have 2 data stores related to the checkout: `wc/store/checkout` [(file)](https://href.li/?https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/index.ts#L1) and `wc/store/payment` [(file)](https://href.li/?https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/payment-methods/index.ts#L1) . Data stores live in the `assets/js/data` folder. ### Contexts @@ -59,25 +57,25 @@ Below is the complete checkout flow The checkout process starts when a user clicks the button -### 2\. Checkout status is set to `before_processing` [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx#L167) +### 2\. Checkout status is set to `before_processing` [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx#L167) As soon as the user clicks the "Place Order" button, we change the checkout status to _"before_processing"_. This is where we handle the validation of the checkout information. -### 3\. Emit the `checkout_validation_before_processing` event [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx#L113) +### 3\. Emit the `checkout_validation_before_processing` event [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/checkout-events/index.tsx#L113) This is where the WooCommerce Blocks plugin and other plugins can register event listeners for dealing with validation. The event listeners for this event will run and if there are errors, we set checkout status to `idle` and display the errors to the user. If there are no errors, we move to step 4 below. -### 4\. Checkout status is set to `processing` [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L76) +### 4\. Checkout status is set to `processing` [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L76) The processing status is used by step 5 below to change the payment status -### 5\. Payment status is set to `processing` [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/payment-methods/payment-method-events-context.tsx#L94) +### 5\. Payment status is set to `processing` [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/payment-methods/payment-method-events-context.tsx#L94) Once all the checkout processing is done and if there are no errors, the payment processing begins -### 6\. Emit the `payment_processing` event [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/payment-methods/thunks.ts#L42) +### 6\. Emit the `payment_processing` event [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/payment-methods/thunks.ts#L42) The `payment_processing` event is emitted. Otherplugins can register event listeners for this event and run their own code. @@ -85,19 +83,19 @@ For example, the Stripe plugin checks the address and payment details here, and **Important note: The actual payment is not taken here**. **It acts like a pre-payment hook to run any payment plugin code before the actual payment is attempted.** -### 7\. Execute the `payment_processing` event listeners and set the payment and checkout states accordingly [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/payment-methods/thunks.ts#L54-L132) +### 7\. Execute the `payment_processing` event listeners and set the payment and checkout states accordingly [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/payment-methods/thunks.ts#L54-L132) If the registered event listeners return errors, we will display this to the user. If the event listeners are considered successful, we sync up the address of the checkout with the payment address, store the `paymentMethodData` in the payment store, and set the payment status property `{ isProcessing: true }`. -### 8\. POST to `/wc/store/v1/checkout` [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/checkout-processor.js#L234) +### 8\. POST to `/wc/store/v1/checkout` [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/checkout-processor.js#L234) The `/checkout` StoreApi endpoint is called if there are no payment errors. This will take the final customer addresses and chosen payment method, and any additional payment data, then attempts payment and returns the result. **Important: payment is attempted through the StoreApi, NOT through the `payment_processing` event that is sent from the client** -### 9\. The `processCheckoutResponse` action is triggered on the checkout store [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L33) +### 9\. The `processCheckoutResponse` action is triggered on the checkout store [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L33) Once the fetch to the StoreApi `/checkout` endpoint returns a response, we pass this to the `processCheckoutResponse` action on the `checkout` data store. @@ -107,25 +105,25 @@ It will perform the following actions: - It stores the payment result in the `checkout` data store. - It changes the checkout status to `after_processing` (step 10) -### 10\. Checkout status is set to `after_processing` [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L42) +### 10\. Checkout status is set to `after_processing` [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L42) The `after_processing` status indicates that we've finished the main checkout processing step. In this step, we run cleanup actions and display any errors that have been triggered during the last step. -### 11\. Emit the `checkout_after_processing_with_success` event [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L118-L128) +### 11\. Emit the `checkout_after_processing_with_success` event [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L118-L128) If there are no errors, the `checkout_after_processing_with_success` event is triggered. This is where other plugins can run some code after the checkout process has been successful. Any event listeners registered on the `checkout_after_processing_with_success` event will be executed. If there are no errors from the event listeners, `setComplete` action is called on the `checkout` data store to set the status to `complete` (step 13). An event listener can also return an error here, which will be displayed to the user. -### 12\. Emit the `checkout_after_processing_with_error` event [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L104-L116) +### 12\. Emit the `checkout_after_processing_with_error` event [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/thunks.ts#L104-L116) If there has been an error from step 5, the `checkout_after_processing_with_error` event will be emitted. Other plugins can register event listeners to run here to display an error to the user. The event listeners are processed and display any errors to the user. -### 13\. Set checkout status to `complete` [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/utils.ts#L146) +### 13\. Set checkout status to `complete` [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/data/checkout/utils.ts#L146) If there are no errors, the `status` property changes to `complete` in the checkout data store. This indicates that the checkout process is complete. -### 14\. Redirect [:file_folder:](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/checkout-processor.js#L193-L197) +### 14\. Redirect [(file)](https://github.com/woocommerce/woocommerce-blocks/blob/4af2c0916a936369be8a4f0044683b90b3af4f0d/assets/js/base/context/providers/cart-checkout/checkout-processor.js#L193-L197) Once the checkout status is set to `complete`, if there is a `redirectUrl` in the checkout data store, then we redirect the user to the URL. diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/integration-interface.md b/docs/cart-and-checkout-blocks/integration-interface.md similarity index 92% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/integration-interface.md rename to docs/cart-and-checkout-blocks/integration-interface.md index 3e3dec71137..61b1e33db52 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/integration-interface.md +++ b/docs/cart-and-checkout-blocks/integration-interface.md @@ -1,24 +1,9 @@ --- post_title: Cart and Checkout - Handling scripts, styles, and data -menu_title: Script, styles, and data handling +menu_title: Script, Styles, and Data Handling tags: how-to --- -# `IntegrationRegistry` and `IntegrationInterface` - -## Table of Contents - -- [The problem](#the-problem) -- [The solution](#the-solution) -- [`IntegrationInterface` methods](#integrationinterface-methods) - - [`get_name()`](#get_name) - - [`initialize()`](#initialize) - - [`get_script_handles()`](#get_script_handles) - - [`get_editor_script_handles()`](#get_editor_script_handles) - - [`get_script_data()`](#get_script_data) -- [Usage example](#usage-example) - - [Getting data added in `get_script_data`](#getting-data-added-in-get_script_data) - ## The problem You are an extension developer, and to allow users to interact with your extension on the client-side, you have written some CSS and JavaScript that you would like to be included on the page. Your JavaScript also relies on some server-side data, and you'd like this to be available to your scripts. diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/slot-fills.md b/docs/cart-and-checkout-blocks/slot-fills.md similarity index 81% rename from plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/slot-fills.md rename to docs/cart-and-checkout-blocks/slot-fills.md index 598d0f1f67c..d694d03bb1e 100644 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/slot-fills.md +++ b/docs/cart-and-checkout-blocks/slot-fills.md @@ -1,22 +1,12 @@ --- -post_title: Cart and Checkout - Slot and Fill +post_title: Cart and Checkout - Slot and fill menu_title: Slot and Fill tags: reference --- -# Slot and Fill - -## Table of Contents - -- [The problem](#the-problem) -- [Solution](#solution) -- [Basic Usage](#basic-usage) -- [registerPlugin](#registerplugin) -- [Requirements](#requirements) - ## The problem -You added custom data to the [Store API](../rest-api/extend-rest-api-add-data.md). You changed several strings using [Checkout filters](./available-filters.md). Now you want to render your own components in specific places in the Cart and Checkout. +You added custom data to the [Store API](https://github.com/woocommerce/woocommerce/blob/1675c63bba94c59703f57c7ef06e7deff8fd6bba/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/extend-rest-api-add-data.md). You changed several strings using [Checkout filters](./category/cart-and-checkout-blocks/available-filters/). Now you want to render your own components in specific places in the Cart and Checkout. ## Solution diff --git a/docs/docs-manifest.json b/docs/docs-manifest.json index c5ec85a7784..cf69b715e95 100644 --- a/docs/docs-manifest.json +++ b/docs/docs-manifest.json @@ -37,16 +37,202 @@ }, { "post_title": "How to add a custom field to simple and variable products", - "menu_title": "Add custom fields to products", + "menu_title": "Add Custom Fields to Products", "tags": "how-to", "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/building-a-woo-store/adding-a-custom-field-to-variable-products.md", - "hash": "72eba9999d9f1a152a10d27df349e666d1c3735fd3f1328a50c69c846dd18bed", + "hash": "59ef97ed2053dedfa5e7c658d5c7fa470d8110afc9b84584cb32b58389bf5687", "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/building-a-woo-store/adding-a-custom-field-to-variable-products.md", "id": "64b686dcd5fdd4842be2fc570108231d5a8bfc1b" } ], "categories": [] }, + { + "content": "", + "category_slug": "cart-and-checkout-blocks", + "category_title": "Cart and Checkout Blocks", + "posts": [ + { + "post_title": "Cart and Checkout - Slot and fill", + "menu_title": "Slot and Fill", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/slot-fills.md", + "hash": "f83a5fbef86e5ef6b0ec1d63fdbcbf4742f54de1125e535fa0f32f5f80ec794a", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/slot-fills.md", + "id": "e388101586765dd9aca752d66d667d74951a1504" + }, + { + "post_title": "Cart and Checkout - Handling scripts, styles, and data", + "menu_title": "Script, Styles, and Data Handling", + "tags": "how-to", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/integration-interface.md", + "hash": "0f69443cf4d6fc672fb1ff02158f81c513e05675c9df0f8f4bc82a7efacbb20c", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/integration-interface.md", + "id": "4e702e6f5d22756c4d3518ee3190320df691878f" + }, + { + "post_title": "Cart and Checkout - How the checkout block processes an order", + "menu_title": "Processing an Order", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/how-checkout-processes-an-order.md", + "hash": "738c3bf03138a084723061bafdc9315a58606c1dad2ab8743d44b7af93e7ecfc", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/how-checkout-processes-an-order.md", + "id": "092e66dac8f44d08799ba1d2411d757fd53c9e00" + }, + { + "post_title": "Cart and Checkout - DOM events", + "menu_title": "DOM Events", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/dom-events.md", + "hash": "5ad212b2ee74a7f85dfe05dfa10a3797d839c4e791cc78998fadf30f8a61adf9", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/dom-events.md", + "id": "d04c25818072f47ec21c36e7907e0f81c9c20cc3" + }, + { + "post_title": "Cart and Checkout - Available slots", + "menu_title": "Available Slots", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/available-slot-fills.md", + "hash": "770da9156eea1fdc24db0736ce4ccd44ebde4f3b0373cd875b1ae88d4d9c8a49", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/available-slot-fills.md", + "id": "c7ac16eee5540b06b6db928f5d03282ff177e84e" + }, + { + "post_title": "Cart and Checkout - Additional checkout fields", + "menu_title": "Additional Checkout Fields", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/additional-checkout-fields.md", + "hash": "e956a9b4c3d57d125daafc850d9a28bd0d626e9498478a15c7fbab540359ed95", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/additional-checkout-fields.md", + "id": "cb5dd8d59043a4e53929121b45da7b33b1661ab8" + } + ], + "categories": [ + { + "content": "\nThis document lists the filters that are currently available to extensions and offers usage information for each one of them. Information on registering filters can be found on the [Checkout - Filter Registry](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/packages/checkout/filter-registry/README.md) page.\n\n## Cart Line Items filters\n\nThe following [Cart Line Items filters](./cart-line-items.md) are available:\n\n- `cartItemClass`\n- `cartItemPrice`\n- `itemName`\n- `saleBadgePriceFormat`\n- `showRemoveItemLink`\n- `subtotalPriceFormat`\n\nThe following screenshot shows which parts the individual filters affect:\n\n![Cart Line Items](https://woocommerce.com/wp-content/uploads/2023/10/Screenshot-2023-10-26-at-13.12.33.png)\n\n## Order Summary Items filters\n\nThe following [Order Summary Items filters](./order-summary-items.md) are available:\n\n- `cartItemClass`\n- `cartItemPrice`\n- `itemName`\n- `subtotalPriceFormat`\n\nThe following screenshot shows which parts the individual filters affect:\n\n![Order Summary Items](https://woocommerce.com/wp-content/uploads/2023/10/Screenshot-2023-10-26-at-16.29.45.png)\n\n## Totals Footer Item filter\n\nThe following [Totals Footer Item filter](./totals-footer-item.md) is available:\n\n- `totalLabel`\n- `totalValue`\n\n## Checkout and place order button filters\n\nThe following [Checkout and place order button filters](./checkout-and-place-order-button.md) are available:\n\n- `proceedToCheckoutButtonLabel`\n- `proceedToCheckoutButtonLink`\n- `placeOrderButtonLabel`\n\n## Coupon filters\n\nThe following [Coupon filters](./coupons.md) are available:\n\n- `coupons`\n- `showApplyCouponNotice`\n- `showRemoveCouponNotice`\n\n## Additional Cart and Checkout inner block types filter\n\nThe following [Additional Cart and Checkout inner block types filter](./additional-cart-checkout-inner-block-types.md) is available:\n\n- `additionalCartCheckoutInnerBlockTypes`\n\n## Combined filters\n\nFilters can also be combined. The following example shows how to combine some of the available filters.\n\n```tsx\nconst { registerCheckoutFilters } = window.wc.blocksCheckout;\n\nconst isOrderSummaryContext = ( args ) => args?.context === 'summary';\n\nconst modifyCartItemClass = ( defaultValue, extensions, args ) => {\n\tif ( isOrderSummaryContext( args ) ) {\n\t\treturn 'my-custom-class';\n\t}\n\treturn defaultValue;\n};\n\nconst modifyCartItemPrice = ( defaultValue, extensions, args ) => {\n\tif ( isOrderSummaryContext( args ) ) {\n\t\treturn ' for all items';\n\t}\n\treturn defaultValue;\n};\n\nconst modifyItemName = ( defaultValue, extensions, args ) => {\n\tif ( isOrderSummaryContext( args ) ) {\n\t\treturn `${ defaultValue }`;\n\t}\n\treturn defaultValue;\n};\n\nconst modifySubtotalPriceFormat = ( defaultValue, extensions, args ) => {\n\tif ( isOrderSummaryContext( args ) ) {\n\t\treturn ' per item';\n\t}\n\treturn defaultValue;\n};\n\nregisterCheckoutFilters( 'example-extension', {\n\tcartItemClass: modifyCartItemClass,\n\tcartItemPrice: modifyCartItemPrice,\n\titemName: modifyItemName,\n\tsubtotalPriceFormat: modifySubtotalPriceFormat,\n} );\n```\n\n## Troubleshooting\n\nIf you are logged in to the store as an administrator, you should be shown an error like this if your filter is not\nworking correctly. The error will also be shown in your console.\n\n![Troubleshooting](https://woocommerce.com/wp-content/uploads/2023/10/Screenshot-2023-10-30-at-10.52.53.png)\n\n\n", + "category_slug": "cart-and-checkout-available-filters", + "category_title": "Available Filters", + "posts": [ + { + "post_title": "Cart and Checkout Filters - Totals footer item", + "menu_title": "Totals Footer Item", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/available-filters/totals-footer-item.md", + "hash": "3a9869d7d7beadb8117c100c3b58675e416e16386ee753f78e1a9087e768053f", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/available-filters/totals-footer-item.md", + "id": "90a9b8df374082f1713866a58b810303adb4d3da" + }, + { + "post_title": "Cart and Checkout Filters - Order summary items", + "menu_title": "Order Summary Items", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/available-filters/order-summary-items.md", + "hash": "36f1bfa8d192b106d28d71334b42413d4c289a0a8d1f5b76b2f905d6fa453883", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/available-filters/order-summary-items.md", + "id": "78eb3b135f82a3624a49979e3e93334295abd060" + }, + { + "post_title": "Cart and Checkout Filters - Coupons", + "menu_title": "Coupons", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/available-filters/coupons.md", + "hash": "9ce61079d75f991137c771f044812c385db165256723a814ed44ba9caf297f13", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/available-filters/coupons.md", + "id": "5a022617f3d0267c9b771374f28970e779a6e99d" + }, + { + "post_title": "Cart and Checkout Filters - Checkout and place order button", + "menu_title": "Checkout and Place Order Button", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/available-filters/checkout-and-place-order-button.md", + "hash": "9ef672160e407cebef3b163414834a6f6f67cd7d677aa399a4312883e0827131", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/available-filters/checkout-and-place-order-button.md", + "id": "c97ca710c2e8107bf90915e038a34c8a1016c63a" + }, + { + "post_title": "Cart and Checkout Filters - Cart line items", + "menu_title": "Cart Line Items", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/available-filters/cart-line-items.md", + "hash": "f83254846b98a94f5c895f4a0a6719b281cba81884edb45e413a644967d28f73", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/available-filters/cart-line-items.md", + "id": "97881b973dc1d08a54c54e0a04ecb75ee48dcee2" + }, + { + "post_title": "Cart and Checkout Filters - Inner block types", + "menu_title": "Inner Block Types", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/available-filters/additional-cart-checkout-inner-block-types.md", + "hash": "10534fe4d38115dd95efb4d791593c3b32db0317239b49ca8101ad744c22fd32", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/available-filters/additional-cart-checkout-inner-block-types.md", + "id": "3167c9602b1bd3b206226a0d4415944a5f647495" + } + ], + "categories": [] + }, + { + "content": "\n\n\n", + "category_slug": "checkout-payment-methods", + "category_title": "Payment Methods", + "posts": [ + { + "post_title": "Cart and Checkout - Payment method integration for the Checkout block", + "menu_title": "Payment Method Integration", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/checkout-payment-methods/payment-method-integration.md", + "hash": "f60acaaea4a6ac4adf637bc7069c966e01db089f9dfaa937def91165a71a4255", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/checkout-payment-methods/payment-method-integration.md", + "id": "c9a763b6976ecf03aeb961577c17c31f1ac7c420", + "links": { + "./checkout-flow-and-events.md": "499384cbb48ed96a2e12653cd68bd82d123a20a1" + } + }, + { + "post_title": "Cart and Checkout - Filtering payment methods in the Checkout block", + "menu_title": "Filtering Payment Methods", + "tags": "how-to", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/checkout-payment-methods/filtering-payment-methods.md", + "hash": "eec74b9116b1c0b76fdd9e50810e5f08467aec90ee62486409ca204be21dc3e4", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/checkout-payment-methods/filtering-payment-methods.md", + "id": "5c9ff65767116f51e9ec4de26794e6e4e743ffa3", + "links": { + "./payment-method-integration.md": "c9a763b6976ecf03aeb961577c17c31f1ac7c420" + } + }, + { + "post_title": "Cart and Checkout - Checkout flow and events", + "menu_title": "Checkout Flow and Events", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/checkout-payment-methods/checkout-flow-and-events.md", + "hash": "dcc4af69b2614b0722431f81a312558bf3c5fa349021849d241bf896e02813a7", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/checkout-payment-methods/checkout-flow-and-events.md", + "id": "499384cbb48ed96a2e12653cd68bd82d123a20a1", + "links": { + "./payment-method-integration.md": "c9a763b6976ecf03aeb961577c17c31f1ac7c420" + } + } + ], + "categories": [] + }, + { + "content": "\n\n\n", + "category_slug": "cart-and-checkout-hooks", + "category_title": "Hooks", + "posts": [ + { + "post_title": "Cart and Checkout - Legacy hooks", + "menu_title": "Legacy Hooks", + "tags": "reference", + "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/cart-and-checkout-blocks/hooks/migrated-hooks.md", + "hash": "025731fc8884e13e09ecc857bee7d669a091f11640e023e40c08ffc521f38964", + "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/cart-and-checkout-blocks/hooks/migrated-hooks.md", + "id": "5264fa45d393327b2c9cffb038c4d3670879d911" + } + ], + "categories": [] + } + ] + }, { "content": "\nAccess a collection of useful code snippets to customize and enhance your WooCommerce store's functionality.\n", "category_slug": "code-snippets", @@ -396,6 +582,13 @@ ], "categories": [] }, + { + "content": "\n\nThese documents are all dealing with extensibility in the various WooCommerce Blocks.\n\n## Imports and dependency extration\n\nThe documentation in this section will use window globals in code examples, for example:\n\n```js\nconst { registerCheckoutFilters } = window.wc.blocksCheckout;\n```\n\nHowever, if you're using `@woocommerce/dependency-extraction-webpack-plugin` for enhanced dependency management you can instead use ES module syntax:\n\n```js\nimport { registerCheckoutFilters } from '@woocommerce/blocks-checkout';\n```\n\nSee for more information.\n\n## Hooks (actions and filters)\n\n| Document | Description |\n| ----------------------------- | ------------------------------------------------------- |\n| [Actions](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/hooks/actions.md) | Documentation covering action hooks on the server side. |\n| [Filters](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/hooks/filters.md) | Documentation covering filter hooks on the server side. |\n| [Migrated Hooks](/docs/cart-and-checkout-legacy-hooks/) | Documentation covering the migrated WooCommerce core hooks. |\n\n## REST API\n\n| Document | Description |\n| ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |\n| [Exposing your data in the Store API.](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/extend-rest-api-add-data.md) | Explains how you can add additional data to Store API endpoints. |\n| [Available endpoints to extend with ExtendSchema](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/available-endpoints-to-extend.md) | A list of all available endpoints to extend. |\n| [Available Formatters](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/extend-rest-api-formatters.md) | Available `Formatters` to format data for use in the Store API. |\n| [Updating the cart with the Store API](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/extend-rest-api-update-cart.md) | Update the server-side cart following an action from the front-end. |\n\n## Checkout Payment Methods\n\n| Document | Description |\n| -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |\n| [Checkout Flow and Events](/docs/cart-and-checkout-checkout-flow-and-events/) | All about the checkout flow in the checkout block and the various emitted events that can be subscribed to. |\n| [Payment Method Integration](/docs/cart-and-checkout-payment-method-integration-for-the-checkout-block/) | Information about implementing payment methods. |\n| [Filtering Payment Methods](/docs/cart-and-checkout-filtering-payment-methods-in-the-checkout-block/) | Information about filtering the payment methods available in the Checkout Block. |\n\n## Checkout Block\n\nIn addition to the reference material below, [please see the `block-checkout` package documentation](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/packages/checkout/README.md) which is used to extend checkout with Filters, Slot Fills, and Inner Blocks.\n\n| Document | Description |\n|--------------------------------------------------------------------------------------------------| ----------------------------------------------------------------------------------------------------------------- |\n| [How the Checkout Block processes an order](/docs/cart-and-checkout-how-the-checkout-block-processes-an-order/) | The detailed inner workings of the Checkout Flow. |\n| [IntegrationInterface](/docs/cart-and-checkout-handling-scripts-styles-and-data/) | The `IntegrationInterface` class and how to use it to register scripts, styles, and data with WooCommerce Blocks. |\n| [Available Filters](/docs/category/cart-and-checkout-blocks/available-filters/) | All about the filters that you may use to change values of certain elements of WooCommerce Blocks. |\n| [Slots and Fills](/docs/cart-and-checkout-slot-and-fill/) | Explains Slot Fills and how to use them to render your own components in Cart and Checkout. |\n| [Available Slot Fills](/docs/cart-and-checkout-available-slots/) | Available Slots that you can use and their positions in Cart and Checkout. |\n| [DOM Events](/docs/cart-and-checkout-dom-events/) | A list of DOM Events used by some blocks to communicate between them and with other parts of WooCommerce. |\n| [Filter Registry](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/packages/checkout/filter-registry/README.md) | The filter registry allows callbacks to be registered to manipulate certain values. |\n| [Additional Checkout Fields](/docs/cart-and-checkout-additional-checkout-fields/) | The filter registry allows callbacks to be registered to manipulate certain values. |\n", + "category_slug": "extensibility-in-blocks", + "category_title": "Extensibility in Blocks", + "posts": [], + "categories": [] + }, { "content": "\nExplore how to develop WooCommerce extensions with practical tutorials and resources ideal for initial setup and understanding the core functionalities of the platform.\n", "category_slug": "extension-development", @@ -848,14 +1041,14 @@ { "post_title": "Extending the product form with generic fields", "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/product-editor-development/how-to-guides/generic-fields-tutorial.md", - "hash": "dc00134aa0a50c6d2e7aa5fb558c2d307fb45ab23cd5a31ab6133eebf83a12bd", + "hash": "a0e68f9d6027f8bcd4ef09cc33d5b3bf8c7169adad89c676569a97a6185dd261", "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/product-editor-development/how-to-guides/generic-fields-tutorial.md", "id": "f221ccb6d42c5e67a0a7916b955253ab7e546641" }, { "post_title": "Extending the product form with custom fields", "edit_url": "https://github.com/woocommerce/woocommerce/edit/trunk/docs/product-editor-development/how-to-guides/custom-field-tutorial.md", - "hash": "fd33aa63a9d397a1df35ef032a6f1f76fd1ab5aac1bccc94e29a56fa8bfc2aa4", + "hash": "f0d0273c0d65739d605448492bfbe684f0ed33f9e6e274df06f26e83cb6ba341", "url": "https://raw.githubusercontent.com/woocommerce/woocommerce/trunk/docs/product-editor-development/how-to-guides/custom-field-tutorial.md", "id": "fed80efbb225df9054fadd6e1fc45c2cd03e7f99" } @@ -1487,5 +1680,5 @@ "categories": [] } ], - "hash": "013248fe7a892f063140734071d4c29205d819e137991f9ea25676c1364f3d66" + "hash": "aba0ae4b152f1007f64966aa21601ba73786ce4b1be4219f18ecbf295ee10221" } \ No newline at end of file diff --git a/docs/extensibility-in-blocks/README.md b/docs/extensibility-in-blocks/README.md new file mode 100644 index 00000000000..492f1775e5c --- /dev/null +++ b/docs/extensibility-in-blocks/README.md @@ -0,0 +1,64 @@ +--- +category_title: Extensibility in Blocks +category_slug: extensibility-in-blocks +post_title: Extensibility in blocks +--- + + +These documents are all dealing with extensibility in the various WooCommerce Blocks. + +## Imports and dependency extration + +The documentation in this section will use window globals in code examples, for example: + +```js +const { registerCheckoutFilters } = window.wc.blocksCheckout; +``` + +However, if you're using `@woocommerce/dependency-extraction-webpack-plugin` for enhanced dependency management you can instead use ES module syntax: + +```js +import { registerCheckoutFilters } from '@woocommerce/blocks-checkout'; +``` + +See for more information. + +## Hooks (actions and filters) + +| Document | Description | +| ----------------------------- | ------------------------------------------------------- | +| [Actions](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/hooks/actions.md) | Documentation covering action hooks on the server side. | +| [Filters](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/hooks/filters.md) | Documentation covering filter hooks on the server side. | +| [Migrated Hooks](/docs/cart-and-checkout-legacy-hooks/) | Documentation covering the migrated WooCommerce core hooks. | + +## REST API + +| Document | Description | +| ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | +| [Exposing your data in the Store API.](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/extend-rest-api-add-data.md) | Explains how you can add additional data to Store API endpoints. | +| [Available endpoints to extend with ExtendSchema](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/available-endpoints-to-extend.md) | A list of all available endpoints to extend. | +| [Available Formatters](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/extend-rest-api-formatters.md) | Available `Formatters` to format data for use in the Store API. | +| [Updating the cart with the Store API](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/rest-api/extend-rest-api-update-cart.md) | Update the server-side cart following an action from the front-end. | + +## Checkout Payment Methods + +| Document | Description | +| -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | +| [Checkout Flow and Events](/docs/cart-and-checkout-checkout-flow-and-events/) | All about the checkout flow in the checkout block and the various emitted events that can be subscribed to. | +| [Payment Method Integration](/docs/cart-and-checkout-payment-method-integration-for-the-checkout-block/) | Information about implementing payment methods. | +| [Filtering Payment Methods](/docs/cart-and-checkout-filtering-payment-methods-in-the-checkout-block/) | Information about filtering the payment methods available in the Checkout Block. | + +## Checkout Block + +In addition to the reference material below, [please see the `block-checkout` package documentation](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/packages/checkout/README.md) which is used to extend checkout with Filters, Slot Fills, and Inner Blocks. + +| Document | Description | +|--------------------------------------------------------------------------------------------------| ----------------------------------------------------------------------------------------------------------------- | +| [How the Checkout Block processes an order](/docs/cart-and-checkout-how-the-checkout-block-processes-an-order/) | The detailed inner workings of the Checkout Flow. | +| [IntegrationInterface](/docs/cart-and-checkout-handling-scripts-styles-and-data/) | The `IntegrationInterface` class and how to use it to register scripts, styles, and data with WooCommerce Blocks. | +| [Available Filters](/docs/category/cart-and-checkout-blocks/available-filters/) | All about the filters that you may use to change values of certain elements of WooCommerce Blocks. | +| [Slots and Fills](/docs/cart-and-checkout-slot-and-fill/) | Explains Slot Fills and how to use them to render your own components in Cart and Checkout. | +| [Available Slot Fills](/docs/cart-and-checkout-available-slots/) | Available Slots that you can use and their positions in Cart and Checkout. | +| [DOM Events](/docs/cart-and-checkout-dom-events/) | A list of DOM Events used by some blocks to communicate between them and with other parts of WooCommerce. | +| [Filter Registry](https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce-blocks/packages/checkout/filter-registry/README.md) | The filter registry allows callbacks to be registered to manipulate certain values. | +| [Additional Checkout Fields](/docs/cart-and-checkout-additional-checkout-fields/) | The filter registry allows callbacks to be registered to manipulate certain values. | diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/README.md b/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/README.md deleted file mode 100644 index bdd1f72a968..00000000000 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/README.md +++ /dev/null @@ -1,77 +0,0 @@ -# Extensibility in WooCommerce Blocks - -## Table of Contents - -- [Imports and dependency extration](#imports-and-dependency-extration) -- [Hooks (actions and filters)](#hooks-actions-and-filters) -- [REST API](#rest-api) -- [Checkout Payment Methods](#checkout-payment-methods) -- [Checkout Block](#checkout-block) - -These documents are all dealing with extensibility in the various WooCommerce Blocks. - -## Imports and dependency extration - -The documentation in this section will use window globals in code examples, for example: - -```js -const { registerCheckoutFilters } = window.wc.blocksCheckout; -``` - -However, if you're using `@woocommerce/dependency-extraction-webpack-plugin` for enhanced dependency management you can instead use ES module syntax: - -```js -import { registerCheckoutFilters } from '@woocommerce/blocks-checkout'; -``` - -See for more information. - -## Hooks (actions and filters) - -| Document | Description | -| ----------------------------- | ------------------------------------------------------- | -| [Actions](./hooks/actions.md) | Documentation covering action hooks on the server side. | -| [Filters](./hooks/filters.md) | Documentation covering filter hooks on the server side. | -| [Migrated Hooks](./hooks/migrated-hooks.md) | Documentation covering the migrated WooCommerce core hooks. | - -## REST API - -| Document | Description | -| ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | -| [Exposing your data in the Store API.](./rest-api/extend-rest-api-add-data.md) | Explains how you can add additional data to Store API endpoints. | -| [Available endpoints to extend with ExtendSchema](./rest-api/available-endpoints-to-extend.md) | A list of all available endpoints to extend. | -| [Available Formatters](./rest-api/extend-rest-api-formatters.md) | Available `Formatters` to format data for use in the Store API. | -| [Updating the cart with the Store API](./rest-api/extend-rest-api-update-cart.md) | Update the server-side cart following an action from the front-end. | - -## Checkout Payment Methods - -| Document | Description | -| -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- | -| [Checkout Flow and Events](./checkout-payment-methods/checkout-flow-and-events.md) | All about the checkout flow in the checkout block and the various emitted events that can be subscribed to. | -| [Payment Method Integration](./checkout-payment-methods/payment-method-integration.md) | Information about implementing payment methods. | -| [Filtering Payment Methods](./checkout-payment-methods/filtering-payment-methods.md) | Information about filtering the payment methods available in the Checkout Block. | - -## Checkout Block - -In addition to the reference material below, [please see the `block-checkout` package documentation](../../../packages/checkout/README.md) which is used to extend checkout with Filters, Slot Fills, and Inner Blocks. - -| Document | Description | -|--------------------------------------------------------------------------------------------------| ----------------------------------------------------------------------------------------------------------------- | -| [How the Checkout Block processes an order](./checkout-block/how-checkout-processes-an-order.md) | The detailed inner workings of the Checkout Flow. | -| [IntegrationInterface](./checkout-block/integration-interface.md) | The `IntegrationInterface` class and how to use it to register scripts, styles, and data with WooCommerce Blocks. | -| [Available Filters](./checkout-block/available-filters.md) | All about the filters that you may use to change values of certain elements of WooCommerce Blocks. | -| [Slots and Fills](./checkout-block/slot-fills.md) | Explains Slot Fills and how to use them to render your own components in Cart and Checkout. | -| [Available Slot Fills](./checkout-block/available-slot-fills.md) | Available Slots that you can use and their positions in Cart and Checkout. | -| [DOM Events](./checkout-block/dom-events.md) | A list of DOM Events used by some blocks to communicate between them and with other parts of WooCommerce. | -| [Filter Registry](../../../packages/checkout/filter-registry/README.md) | The filter registry allows callbacks to be registered to manipulate certain values. | -| [Additional Checkout Fields](./checkout-block/additional-checkout-fields.md) | The filter registry allows callbacks to be registered to manipulate certain values. | - - - ---- - -[We're hiring!](https://woocommerce.com/careers/) Come work with us! - -🐞 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/README.md) - - diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters.md b/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters.md deleted file mode 100644 index b64b35c74e7..00000000000 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-block/available-filters.md +++ /dev/null @@ -1,129 +0,0 @@ ---- -post_title: Cart and Checkout - Available Filters -menu_title: Available Filters -tags: reference ---- - -# Available filters - -## Table of Contents - -- [Cart Line Items filters](#cart-line-items-filters) -- [Order Summary Items filters](#order-summary-items-filters) -- [Totals Footer Item filter](#totals-footer-item-filter) -- [Checkout and place order button filters](#checkout-and-place-order-button-filters) -- [Coupon filters](#coupon-filters) -- [Additional Cart and Checkout inner block types filter](#additional-cart-and-checkout-inner-block-types-filter) -- [Combined filters](#combined-filters) -- [Troubleshooting](#troubleshooting) - -This document lists the filters that are currently available to extensions and offers usage information for each one of them. Information on registering filters can be found on the [Checkout - Filter Registry](../../../../packages/checkout/filter-registry/README.md) page. - -## Cart Line Items filters - -The following [Cart Line Items filters](./available-filters/cart-line-items.md) are available: - -- [`cartItemClass`](./available-filters/cart-line-items.md#cartitemclass) -- [`cartItemPrice`](./available-filters/cart-line-items.md#cartitemprice) -- [`itemName`](./available-filters/cart-line-items.md#itemname) -- [`saleBadgePriceFormat`](./available-filters/cart-line-items.md#salebadgepriceformat) -- [`showRemoveItemLink`](./available-filters/cart-line-items.md#showremoveitemlink) -- [`subtotalPriceFormat`](./available-filters/cart-line-items.md#subtotalpriceformat) - -The following screenshot shows which parts the individual filters affect: - -![Cart Line Items](https://woocommerce.com/wp-content/uploads/2023/10/Screenshot-2023-10-26-at-13.12.33.png) - -## Order Summary Items filters - -The following [Order Summary Items filters](./available-filters/order-summary-items.md) are available: - -- [`cartItemClass`](./available-filters/order-summary-items.md#cartitemclass) -- [`cartItemPrice`](./available-filters/order-summary-items.md#cartitemprice) -- [`itemName`](./available-filters/order-summary-items.md#itemname) -- [`subtotalPriceFormat`](./available-filters/order-summary-items.md#subtotalpriceformat) - -The following screenshot shows which parts the individual filters affect: - -![Order Summary Items](https://woocommerce.com/wp-content/uploads/2023/10/Screenshot-2023-10-26-at-16.29.45.png) - -## Totals Footer Item filter - -The following [Totals Footer Item filter](./available-filters/totals-footer-item.md) is available: - -- [`totalLabel`](./available-filters/totals-footer-item.md#totallabel) -- [`totalValue`](./available-filters/totals-footer-item.md#totalvalue) - -## Checkout and place order button filters - -The following [Checkout and place order button filters](./available-filters/checkout-and-place-order-button.md) are available: - -- [`proceedToCheckoutButtonLabel`](./available-filters/checkout-and-place-order-button.md#proceedtocheckoutbuttonlabel) -- [`proceedToCheckoutButtonLink`](./available-filters/checkout-and-place-order-button.md#proceedtocheckoutbuttonlink) -- [`placeOrderButtonLabel`](./available-filters/checkout-and-place-order-button.md#placeorderbuttonlabel) - -## Coupon filters - -The following [Coupon filters](./available-filters/coupons.md) are available: - -- [`coupons`](./available-filters/coupons.md#coupons-1) -- [`showApplyCouponNotice`](./available-filters/coupons.md#showapplycouponnotice) -- [`showRemoveCouponNotice`](./available-filters/coupons.md#showremovecouponnotice) - -## Additional Cart and Checkout inner block types filter - -The following [Additional Cart and Checkout inner block types filter](./available-filters/additional-cart-checkout-inner-block-types.md) is available: - -- [`additionalCartCheckoutInnerBlockTypes`](./available-filters/additional-cart-checkout-inner-block-types.md#additionalcartcheckoutinnerblocktypes) - -## Combined filters - -Filters can also be combined. The following example shows how to combine some of the available filters. - -```tsx -const { registerCheckoutFilters } = window.wc.blocksCheckout; - -const isOrderSummaryContext = ( args ) => args?.context === 'summary'; - -const modifyCartItemClass = ( defaultValue, extensions, args ) => { - if ( isOrderSummaryContext( args ) ) { - return 'my-custom-class'; - } - return defaultValue; -}; - -const modifyCartItemPrice = ( defaultValue, extensions, args ) => { - if ( isOrderSummaryContext( args ) ) { - return ' for all items'; - } - return defaultValue; -}; - -const modifyItemName = ( defaultValue, extensions, args ) => { - if ( isOrderSummaryContext( args ) ) { - return `πŸͺ΄ ${ defaultValue } πŸͺ΄`; - } - return defaultValue; -}; - -const modifySubtotalPriceFormat = ( defaultValue, extensions, args ) => { - if ( isOrderSummaryContext( args ) ) { - return ' per item'; - } - return defaultValue; -}; - -registerCheckoutFilters( 'example-extension', { - cartItemClass: modifyCartItemClass, - cartItemPrice: modifyCartItemPrice, - itemName: modifyItemName, - subtotalPriceFormat: modifySubtotalPriceFormat, -} ); -``` - -## Troubleshooting - -If you are logged in to the store as an administrator, you should be shown an error like this if your filter is not -working correctly. The error will also be shown in your console. - -![Troubleshooting](https://woocommerce.com/wp-content/uploads/2023/10/Screenshot-2023-10-30-at-10.52.53.png) diff --git a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/checkout-flow-and-events.md b/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/checkout-flow-and-events.md deleted file mode 100644 index bcadd370160..00000000000 --- a/plugins/woocommerce-blocks/docs/third-party-developers/extensibility/checkout-payment-methods/checkout-flow-and-events.md +++ /dev/null @@ -1,16 +0,0 @@ -# Checkout Flow and Events - -To see the Checkout Flow and Events please consult the following document: - -[Checkout Flow and Events](../../../../docs/internal-developers/block-client-apis/checkout/checkout-flow-and-events.md) - - - ---- - -[We're hiring!](https://woocommerce.com/careers/) Come work with us! - -🐞 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/checkout-payment-methods/checkout-flow-and-events.md) - - - diff --git a/plugins/woocommerce/changelog/GIT STATUS b/plugins/woocommerce/changelog/GIT STATUS new file mode 100644 index 00000000000..adaa301ed01 --- /dev/null +++ b/plugins/woocommerce/changelog/GIT STATUS @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +move part of checkout docs to main docs folder