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