daily pastebin goal
16%
SHARE
TWEET

WooCommerce - show cents within a sup tag

lorro Feb 12th, 2018 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   // WooCommerce - show cents within a sup tag
  3.   add_filter( 'wc_price', 'my_price', 3, 60 );
  4.   function my_price( $return, $price, $args ) {
  5.     // $return = price with currency symbol
  6.     // $price = price as a number
  7.     // $args = array (inc tax, exc tax)
  8.     $price = str_replace( ',', '', $price );
  9.     $dollars = intval( $price );
  10.     $cents = intval( ( $price - $dollars ) * 100 + 0.0001 ); // add a little bit for rounding errors
  11.     // ensure $cents has 2 characters
  12.     $cents_str = str_pad( $cents, 2, '0' );
  13.     return '$'.$dollars.'<sup>'.$cents_str.'</sup>';
  14.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top