Cart Line Items » itemName / subtotalPriceFormat / showRemoveItemLink: Add code snippet and screenshot (https://github.com/woocommerce/woocommerce-blocks/pull/10969)

* Cart Line Items » itemName: Add code snippet and screenshot

* subtotalPriceFormat

* showRemoveItemLink
This commit is contained in:
Brian 2023-09-16 07:30:33 +02:00 committed by GitHub
parent 067626a155
commit 181df639d5
1 changed files with 66 additions and 0 deletions

View File

@ -42,6 +42,72 @@ The following filters are available for line items:
Each of these filters has the following arguments passed to it: `{ context: 'cart', cartItem: CartItem }` ([CartItem](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/c00da597efe4c16fcf5481c213d8052ec5df3766/assets/js/type-defs/cart.ts#L113))
### itemName
```ts
const { registerCheckoutFilters } = window.wc.blocksCheckout;
// Adjust item name of the cart line items.
registerCheckoutFilters( 'example-extension', {
itemName: ( value, extensions, args ) => {
// Return early since this filter is not being applied in the Cart context.
// We must return the original value we received here.
if ( args?.context !== 'cart' ) {
return value;
}
return '🪴 ' + value + ' 🪴';
}
} );
```
| Before | After |
| ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| <img width="761" alt="image" src="https://user-images.githubusercontent.com/6242098/268245369-6cd0aad9-4a7e-45e1-915b-3294db101246.png"> | <img width="761" alt="image" src="https://user-images.githubusercontent.com/3323310/267216388-08bc3af0-6290-4ec4-b7f5-5ee21d66ed7f.png"> |
### subtotalPriceFormat
```ts
const { registerCheckoutFilters } = window.wc.blocksCheckout;
// Adjust subtotal price format of the cart line items.
registerCheckoutFilters( 'example-extension', {
subtotalPriceFormat: ( value, extensions, args ) => {
// Return early since this filter is not being applied in the Cart context.
// We must return the original value we received here.
if ( args?.context !== 'cart' ) {
return value;
}
return '<price/> per item';
}
} );
```
| Before | After |
| ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| <img width="761" alt="image" src="https://user-images.githubusercontent.com/6242098/268294925-a014c8d7-4c26-4a0a-8f4c-f74a8240bbb4.png"> | <img width="761" alt="image" src="https://user-images.githubusercontent.com/3323310/267226443-67f089bd-95d0-49f8-81f4-df2fec1a3d69.png"> |
### showRemoveItemLink
```ts
const { registerCheckoutFilters } = window.wc.blocksCheckout;
// Show remove item link of the cart line items.
registerCheckoutFilters( 'example-extension', {
showRemoveItemLink: ( value, extensions, args ) => {
// Return early since this filter is not being applied in the Cart context.
// We must return the original value we received here.
if ( args?.context !== 'cart' ) {
return value;
}
return false;
}
} );
```
| Before | After |
| ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| <img width="761" alt="image" src="https://user-images.githubusercontent.com/6242098/268295858-ec76f525-e2cf-468c-9634-ae9e84e5aa48.png"> | <img width="761" alt="image" src="https://user-images.githubusercontent.com/6242098/268295935-3171cd92-33f1-4182-b875-bc7e422771a0.png"> |
## Order Summary Items
In the Checkout block, there is a sidebar that contains a summary of what the customer is about to purchase. There are some filters available to modify the way certain elements are displayed on each item. The sale badges are not shown here, so those filters are not applied in the Order Summary.