• Resolved harvey_slash

    (@harvey_slash)


    I would like the thousands separator in woocommerce products the ‘indian’ way:
    eg.

    10,00,000 instead of 1,000,000.

    is there any way this can be done ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Have you looked into WooCommerce docs regarding currencies?

    Turn off the the Thousand Separator and Decimal Separator in WC Settings, then try this code in your functions.php

    add_filter( 'formatted_woocommerce_price', 'wc_indian_price_html', 100, 1 );
    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;
    }
    Thread Starter harvey_slash

    (@harvey_slash)

    @safeer, Thanks for your response. Your code works perfectly. But when I enable decimal , it screws up.

    Thanks a lot though

    Thanks,

    Yeah, that’s why i mentioned to disable it, this thing is decimal filter apply. I put up a git here, if you got any suggestion, please send a pull ??

    https://github.com/thecodepoetry/Woocommerce-Indian-currency-format
    https://www.thecodepoetry.com/woocommerce-indian-currency-format/

    Regards
    Safeer

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Woocommerce Product Separator.’ is closed to new replies.