From WPCS version 2.1.5/1.1.5 it is possible with 2 next hooks: wpcs_announce_aggregator and wpcs_add_aggregator_processor in file functions.php of the current wordpress theme. Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | add_action('wpcs_announce_aggregator', function($aggregators) { $aggregators['hello_world'] = 'My own aggregator'; return $aggregators; }); add_action('wpcs_add_aggregator_processor', function($aggregator_key, $currency_name) { global $WPCS; $request = []; //ratesapi.io as an example if ($aggregator_key === 'hello_world') { $query_url = 'https://api.ratesapi.io/api/latest?base=' . $WPCS->default_currency . '&symbols=' . $currency_name; if (function_exists('curl_init')) { $res = $WPCS->file_get_contents_curl($query_url); } else { $res = file_get_contents($query_url); } $data = json_decode($res, true); $request = isset($data['rates'][$currency_name]) ? $data['rates'][$currency_name] : 0; if (!$request) { $request = sprintf("no data for %s", $currency_name); } } return $request; }, 10, 2); |
WPML: open functions.php of your current wp theme drop there next PHP code:
| add_filter('wp_head', function() { $lang = ICL_LANGUAGE_CODE; global $WPCS; switch ($lang) { case 'bg': $WPCS->storage->set_val('wpcs_current_currency', 'BGN'); break; case 'en': $WPCS->storage->set_val('wpcs_current_currency', 'EUR'); break; default: $WPCS->storage->set_val('wpcs_current_currency', 'USD'); break; } }); |
See WPML docs about languages codes Polylang: open functions.php of your current wp theme drop there next PHP code:
| add_filter('wp_head', function() { $lang = get_locale(); global $WPCS; switch ($lang) { case 'bg_BG': $WPCS->storage->set_val('wpcs_current_currency', 'BGN'); break; case 'en_GB': $WPCS->storage->set_val('wpcs_current_currency', 'EUR'); break; default: $WPCS->storage->set_val('wpcs_current_currency', 'USD'); break; } }); |
https://wordpress.org/support/topic/switch-currency-with-language-change-polylang/ See Polylang docs about languages codes GTranslate: open functions.php of your current wp theme drop there next PHP code:
| add_filter('wp_head', function() { $lang = isset($_SERVER['HTTP_X_GT_LANG']) ? $_SERVER['HTTP_X_GT_LANG'] : ''; global $WPCS; switch ($lang) { case 'bg_BG': $WPCS->storage->set_val('wpcs_current_currency', 'BGN'); break; case 'en_GB': $WPCS->storage->set_val('wpcs_current_currency', 'EUR'); break; default: $WPCS->storage->set_val('wpcs_current_currency', 'USD'); break; } }); |
[…]
Install plugin https://wordpress.org/plugins/shortcode-in-menus/ Go to menu page wp-admin/nav-menus.php Drop shortcode [wpcs] or [wpcs_price] into navigation label textinput with any text you want p.s. Possible CSS incompatibilities which should be resolved by you or your site developer
Use for it next plugin: https://wordpress.org/plugins/shortcode-in-menus/
Sometimes some customers need manipulation with currency rates, for example add to USD rate 10%. Every body has its own logic and Math. This article just show how to do this. open your theme functions.php on the same bottom of the file write next code:
| add_filter('wpcs_currency_data_manipulation', 'wpcs_currency_data_manipulation', 1, 1); function wpcs_currency_data_manipulation($currencies) { foreach ($currencies as $key => $value) { if ($key == 'USD') { $currencies[$key]['rate'] = $value['rate'] + 0.10*$value['rate'];//add 10% break; } } return $currencies; } |
Sometimes customer want to place links for currencies changing into his site header.php. Or smth another… But if to place link simply as: <a href=”/?currency=USD”>USD</a> – it will redirect user to the main page – what is not convenient. In such case JavaScript can help you! Drop links with the currencies you are need into the place […]