Decimals as Superscript with decimal separator trong Woocommerce
10th Jun 2021If you want the decimal separator in the superscript, you can easily do that too. If you look at our filter, it has an argument called $decimal_separator. This is the same separator which we have set in the WooCommerce settings. We just have to include that in our final result.
Here is an example –
<?php add_filter( 'formatted_woocommerce_price', 'ts_woo_decimal_price', 10, 5 ); function ts_woo_decimal_price( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) { $unit = number_format( intval( $price ), 0, $decimal_separator, $thousand_separator ); $decimal = sprintf( '%02d', ( $price - intval( $price ) ) * 100 ); return $unit . '<sup>' . $decimal_separator. $decimal . '</sup>'; }
Whatever text we add inside the <sup> tags will be displayed as superscript. Here is the screenshot of the product page –
Add new comment