Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // WooCommerce - show cents within a sup tag
- add_filter( 'wc_price', 'my_price', 3, 60 );
- function my_price( $return, $price, $args ) {
- // $return = price with currency symbol
- // $price = price as a number
- // $args = array (inc tax, exc tax)
- $price = str_replace( ',', '', $price );
- $dollars = intval( $price );
- $cents = intval( ( $price - $dollars ) * 100 + 0.0001 ); // add a little bit for rounding errors
- // ensure $cents has 2 characters
- $cents_str = str_pad( $cents, 2, '0' );
- return '$'.$dollars.'<sup>'.$cents_str.'</sup>';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement