• Resolved velicuicristian

    (@velicuicristian)


    Hello guys ??

    I need some help.

    I whant to put price decimal in <sup> tag..

    Any help ?

    Thx

Viewing 3 replies - 1 through 3 (of 3 total)
  • Try this snippet:

    <?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>';
      }

    The code goes in your child theme’s functions.php or you can use the “My Custom Functions” plugin.

    Thread Starter velicuicristian

    (@velicuicristian)

    Not working good ??

    Sean Cull

    (@seanreloaded)

    Automattic Happiness Engineer

    That code is working on my test site. Could you please elaborate a bit more on what’s not working for you?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Price decimal SUP’ is closed to new replies.