Created
October 6, 2018 20:43
-
-
Save debabratakarfa/e363fbff7d6c2883f81f9ef09a86ca37 to your computer and use it in GitHub Desktop.
WooCommerce Currency convertions
This file contains 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
add_filter( 'wc_price', 'my_custom_price_format', 10, 3 ); | |
function my_custom_price_format( $formatted_price, $price, $args ) { | |
$convertion_rate = 0.000066; | |
$price = filter_var($price, FILTER_SANITIZE_NUMBER_INT)/100; | |
$new_price = $price * $convertion_rate; | |
$price_usd = number_format($new_price, 2 ); | |
// the currency symbol for US dollars | |
$currency = 'USD'; | |
$currency_symbol = '$'; | |
$price_usd = $currency_symbol.$price_usd; // adding currency symbol | |
// The USD formatted price | |
$formatted_price_usd = "<span class='price-usd'> (USD $price_usd)</span>"; | |
// Return both formatted currencies | |
return $formatted_price . $formatted_price_usd; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment