How to get WooCommerce price in decimals superscript, or subscript.

Posted in Code Tips

This snippet will help you strip down the price markup from WooCommerce. On a recent project I used this to add <sup></sup> to the last two decimals for the shopping basket in the header. However you could use this for a number of things.

// Get the total of the cart
$total = $woocommerce->cart->get_cart_total();

// Split the total
$price = explode('.', $total);

// Echo out the new total with <sup>
echo "$price[0].<sup>$price[1]</sup>";

Really simple and quite useful.

I hope you find this tip useful. If you have any comments or would like to know more, please leave me a comment and I will get back to you.

Share this

AG Bot (BETA) - Not live chat

Ask our bot about our products.

Welcome to our AG Bot, powered by OpenAI and trained on our documents and product pages. By continuing to use this service, please keep in mind:

Your continued use indicates acceptance of these terms. We hope you find our AI Chatbot useful!

Hello! I am AG Bot, how can I help you? (Not live chat)