• Resolved gonzalesc

    (@gonzalesc)


    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:

    Text

    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?

Viewing 1 replies (of 1 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @gonzalesc

    For reference, this particular forum is meant for general support with the core functionality of WooCommerce itself. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get some further insight/information.

Viewing 1 replies (of 1 total)
  • The topic ‘Modify cart item subtotal format in the WooCommerce cart block’ is closed to new replies.