Skip to content

Instantly share code, notes, and snippets.

@debabratakarfa
Created October 6, 2018 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save debabratakarfa/e363fbff7d6c2883f81f9ef09a86ca37 to your computer and use it in GitHub Desktop.
Save debabratakarfa/e363fbff7d6c2883f81f9ef09a86ca37 to your computer and use it in GitHub Desktop.
WooCommerce Currency convertions
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