Display Cart Subtotal in Header

This snippet shows how to display the cart subtotal in the header of your website, providing a quick overview for customers.

PHP

function display_cart_subtotal_in_header() {
    if ( WC()->cart->is_empty() ) {
        echo 'Cart: Empty';
    } else {
        echo 'Cart: ' . WC()->cart->get_cart_subtotal();
    }
}
// Use this function in your header.php or with a shortcode

Snippet Feedback

Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.
SHARED BY

Tags

Language

Did it work?

Save Snippet

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.