How to Display the Cart Total in Your Shopify Header
If you want to show the total price of items in the cart directly in your Shopify store’s header, follow these step-by-step instructions. This customization requires editing code, so make sure to follow the steps carefully.
Step 1: Access Your Shopify Theme Files
- Login to Shopify: Log in to your Shopify account and navigate to your Shopify admin dashboard.
- Access Theme Editor: From the Shopify admin dashboard, go to
Online Store
>Themes
. Find the theme you want to edit and clickActions
>Edit code
.
Step 2: Create a New Section File
- Create
cart-total.liquid
: In the theme editor, under theSections
directory, clickAdd a new section
. Name the filecart-total.liquid
and clickCreate section
. - Add Liquid Code: Paste the following code into the new
cart-total.liquid
file:
{{ cart.total_price | money }}
Step 3: Update cart.js
File
- Find
cart.js
: In the theme editor, locate theassets
directory and find thecart.js
file. - Update
getSectionsToRender()
: Insidecart.js
, find thegetSectionsToRender()
function and add the following code below the chat bubble section:
{
id: 'cart-total',
section: 'cart-total',
selector: '.shopify-section'
}
Step 4: Update cart-notification.js
File
- Find
cart-notification.js
: Similarly, in theassets
directory, locate thecart-notification.js
file. - Update
getSectionsToRender()
: Insidecart-notification.js
, find thegetSectionsToRender()
function and add the following code to include the cart total section:
{
id: 'cart-total'
}
Step 5: Place Code in header.liquid
- Find
header.liquid
: In the theme editor, navigate to theSections
directory and find theheader.liquid
file. - Paste Before Cart Icon Link: Paste the following code just before the cart icon link in
header.liquid
:
<style>
.total-container {
display: grid;
place-items: center;
}
</style>
<div class="total-container" id="cart-total">
<span class="centered-text">{{ cart.total_price | money }}</span>
</div>
PASTE THE CODE BELOW THE LINE NOW THIS TEXT USUALLY by line 319
<a href="{{ routes.cart_url }}" class="header__icon header__icon--cart link focus-inset" id="cart-icon-bubble">
Step 6: Save Changes and Test
- Save Changes: After making the edits, click
Save
to save the changes to your theme files. - Test the Display: Visit your Shopify store and add items to the cart. The total price should now be displayed in the header.
That’s it! You’ve successfully added the cart total to your Shopify header. If you encounter any issues, double-check the code and ensure you’ve followed the steps correctly.