Created
July 28, 2014 21:13
-
-
Save BFTrick/02653b97fc3351fc3606 to your computer and use it in GitHub Desktop.
Format the decimals according to wc_format_decimal()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: WooCommerce Format Decimal Tester | |
| * Plugin URI: https://gist.github.com/BFTrick/02653b97fc3351fc3606 | |
| * Description: Test the wc_format_decimal() function. | |
| * Author: Patrick Rauland | |
| * Author URI: http://speakinginbytes.com/ | |
| * Version: 1.0 | |
| * | |
| * This program is free software: you can redistribute it and/or modify | |
| * it under the terms of the GNU General Public License as published by | |
| * the Free Software Foundation, either version 3 of the License, or | |
| * (at your option) any later version. | |
| * | |
| * This program is distributed in the hope that it will be useful, | |
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| * GNU General Public License for more details. | |
| * | |
| * You should have received a copy of the GNU General Public License | |
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| * | |
| */ | |
| if ( ! class_exists( 'WC_Format_Decimal_Tester' ) ) : | |
| class WC_Format_Decimal_Tester { | |
| /** | |
| * Initialize the plugin. | |
| * | |
| * @since 1.0 | |
| */ | |
| public function __construct() { | |
| add_action( 'plugins_loaded', array( $this, 'test' ) ); | |
| } | |
| public function test() { | |
| if ( class_exists( 'WooCommerce' ) && function_exists( 'wc_format_decimal' ) ) { | |
| $numbers = array('2', '2.0', '2.2', '2.200', '2,2', '2,200'); | |
| foreach( $numbers as $key => $number ) { | |
| echo $number . " after wc_format_decimal() is: " . wc_format_decimal( $number, '', true ); | |
| echo "<br/>"; | |
| } | |
| } | |
| } | |
| } | |
| $WC_Format_Decimal_Tester = new WC_Format_Decimal_Tester( __FILE__ ); | |
| endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment