In the cart shortcode, I use the woocommerce_cart_item_subtotal
hook to display the item subtotal using wc_format_sale_price()
, because I’m showing a deal.
Here is the code:
$subtotal = wc_format_sale_price(
$price1,
$price2,
);
Here is a screenshot:
Now, I need to put this item subtotal format in the cart block, here I found and example to modify it:
document.addEventListener('DOMContentLoaded', function() {
const { registerCheckoutFilters } = window.wc.blocksCheckout;
// Adjust cart item price of the cart line items.
registerCheckoutFilters( 'example-extension', {
cartItemPrice: ( 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/> for all items';
}
} );
});
But, if I change <price />
for any other value, it shows an error.
How can I use the SalePrice
component in this section?