To change thousands separator in Woocommerce to Indian format 10,00,000 instead of 1,000,000.
Important: You need to turn off the the Thousand Separator and Decimal Separator in WC Settings to work this.
add_filter( 'formatted_woocommerce_price', 'wc_indian_price_html', 100, 1 ); function wc_indian_price_html( $price ){ setlocale(LC_MONETARY, 'en_IN'); $amount = money_format('%!i', $price); return $amount; } //The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows. below is pure Pure PHP Implementation. function wc_indian_price_html( $price ){ $explrestunits = "" ; if(strlen($price)>3){ $lastthree = substr($price, strlen($price)-3, strlen($price)); $restunits = substr($price, 0, strlen($price)-3); // extracts the last three digits $restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping. $expunit = str_split($restunits, 2); for($i=0; $i<sizeof($expunit); $i++){ // creates each of the 2's group and adds a comma to the end if($i==0) { $explrestunits .= (int)$expunit[$i].","; // if is first value , convert into integer }else{ $explrestunits .= $expunit[$i].","; } } $thecash = $explrestunits.$lastthree; } else { $thecash = $price; } return $thecash; }
If you have any suggestions or a better idea, please send a me pull request on git.
where to add the code?