Allows to manipulate with currencies before showing their drop-downs on the front, example:
| add_filter('wpcs_currency_manipulation_before_show', function($currencies) { $any_conditions = true; if ($any_conditions) { unset($currencies['RUB']); unset($currencies['GBP']); } return $currencies; }); |
Structure of the data in variable $currencies in the example above is:
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | Array ( [USD] => Array ( [name] => USD [rate] => 1 [symbol] => $ [position] => left [is_etalon] => 1 [hide_cents] => 0 [description] => United States dollar [flag] => '' ) [GBP] => Array ( [name] => GBP [rate] => 0.80 [symbol] => £ [position] => left [is_etalon] => 0 [hide_cents] => 0 [description] => British pound [flag] => '' ) [UAH] => Array ( [name] => UAH [rate] => 26.069684 [symbol] => грн. [position] => left [is_etalon] => 0 [hide_cents] => 0 [description] => Украинская гривна [flag] => '' ) [RUB] => Array ( [name] => RUB [rate] => 62.218399 [symbol] => руб. [position] => left [is_etalon] => 0 [hide_cents] => 0 [description] => Российский рубль [flag] => '' ) ) |
from ver.2.1.2/1.1.2
Manipulation on the price by hook, for example rounding. Hook is in public function price().
| add_filter('wpcs_price', function($price) { //http://stackoverflow.com/questions/11692770/rounding-to-nearest-50-cents //return $price = round($price * 2, 0) / 2; return round($price, 0, PHP_ROUND_HALF_EVEN); }); |
Use this hook if you want to add any additional information text after the price string.
| add_filter('wpcs_price_html_tail', function($price_html) { return $price_html . "<strong>Hello World!</strong>"; }); |
This hook allows manipulations with view of the currency switcher if its necessary.
| public function get_drop_down_view() { return apply_filters('wpcs_drop_down_view', $this->get_option('wpcs_drop_down_view', 'ddslick')); } |
For example if you want to change currency switcher view in mobile browsers:
| add_filter('wpcs_drop_down_view', 'wpcs_drop_down_view', 999); function wpcs_drop_down_view($view) { if (wp_is_mobile()) { return 'no'; } return $view; } |
Possible values: no ddslick chosen chosen_dark wselect flags
Hook in public function init_currency_symbols which allows manipulate by currency symbols in the plugin.
| public function init_currency_symbols() { $this->currency_symbols = array( '$', '€', '¥', 'руб.', 'грн.', '₩', 'TL', 'د.إ', '৳', 'R$', 'лв.', 'kr', 'R', 'Kč', 'RM', 'kr.', 'Ft', 'Rp', 'Rs', 'Kr.', '₪', '₱', 'zł', 'kr', 'CHF', 'NT$', '฿', '£', 'lei', '₫', '₦', 'Kn', '-----' ); $this->currency_symbols = apply_filters('wpcs_currency_symbols', array_merge($this->currency_symbols, $this->get_customer_signs())); } |
This hook uses in public function get_currencies of the plugin:
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 30 31 32 33 34 35 36 37 38 | public function get_currencies() { $default = array( 'USD' => array( 'name' => 'USD', 'rate' => 1, 'symbol' => '$', 'position' => 'right', 'is_etalon' => 1, 'description' => 'USA dollar', 'hide_cents' => 0, 'flag' => '', ), 'EUR' => array( 'name' => 'EUR', 'rate' => 0.89, 'symbol' => '€', 'position' => 'left_space', 'is_etalon' => 0, 'description' => 'Europian Euro', 'hide_cents' => 0, 'flag' => '', ) ); $currencies = get_option('wpcs', $default); $currencies = apply_filters('wpcs_currency_data_manipulation', $currencies); if (empty($currencies) OR ! is_array($currencies)) { $currencies = $default; } return $currencies; } |
So you can use it for any manipulations with the currencies data. Example:
| add_filter('wpcs_currency_data_manipulation', 'my_wpcs_currency_data_manipulation', 1, 1); function my_wpcs_currency_data_manipulation($currencies) { foreach ($currencies as $key => $value) { if ($key == 'USD') { $currencies[$key]['rate'] = $value['rate'] + 0.10; break; } } return $currencies; } |