Allows to manipulate with currencies before showing their drop-downs on the front, example:
| add_filter('woocs_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 51 52 53 54 | Array ( [USD] => Array ( [name] => USD [rate] => 1 [symbol] => $ [position] => left [is_etalon] => 1 [hide_cents] => 0 [decimals] => 2 [description] => United States dollar [flag] => '' ) [GBP] => Array ( [name] => GBP [rate] => 0.80 [symbol] => £ [position] => left [is_etalon] => 0 [hide_cents] => 0 [decimals] => 2 [description] => British pound [flag] => '' ) [UAH] => Array ( [name] => UAH [rate] => 26.069684 [symbol] => грн. [position] => left [is_etalon] => 0 [hide_cents] => 0 [decimals] => 2 [description] => Украинская гривна [flag] => '' ) [RUB] => Array ( [name] => RUB [rate] => 62.218399 [symbol] => руб. [position] => left [is_etalon] => 0 [hide_cents] => 0 [decimals] => 2 [description] => Российский рубль [flag] => '' ) ) |
from ver.2.2.4/1.2.4
Hook for fixed prices. Need for compatibility with other plugins, for example: https://currency-switcher.com/woocommerce-extra-product-options-themecomplete/
Allows to cut from cart and checkout page ‘format of price’ provided by ‘Custom price format’ plugin option. By default return TRUE, but its possible return FALSE
| add_action( 'woocs_cut_cart_price_format', function(){ return FALSE; }); |
Allows to change WOOCS form method from POST to GET
| add_action( 'woocs_form_method', function(){ return 'get'; }); |
From 2.2.0/1.20
Works in index.php -> public function woocommerce_variation_prices -> can be used for any manipulations with variable prices, for example rounding of them. Add next code in functions.php of your current wp theme: Example:
| add_filter('woocs_woocommerce_variation_prices', function($price) { return round($price * 2, 0) / 2; }); |
The hook is applied in file wp-content\plugins\woocommerce-currency-switcher\views\shortcodes\woocs.php for the text manipulation in the switchers drop-down. Example:
| add_filter('woocs_currname_in_option', function($currency_name){ //return "Hello " . $currency_name . '!!'; return ""; }); |
Use it by your own logic. Customer request: How can i make sure that there is only a currency symbol in the dropdown without editing the plugin files, so updates are possible. DDSlick dropdown preferred
Use this hook to manipulate by price values, for example rounding price by your own logic. Examples: https://currency-switcher.com/how-to-round-price-to-50-cents/ – rounding price to the nearest 50 cents
| add_filter('woocs_raw_woocommerce_price', function($price) { return round($price * 2, 0) / 2; }); |
https://currency-switcher.com/round-prices-500/ – How to round prices to 500
| add_filter('woocs_raw_woocommerce_price', function($price) { if (($price <= 1000)) { $price = round($price / 1000, 0) * 1000; return $price; } else { $price = ceil($price / 500) * 500; return $price; } }); |
https://currency-switcher.com/how-to-round-price-to-99-cents/ – How to round prices to x.99 Also read: https://currency-switcher.com/hook/woocs_woocommerce_variation_prices/
Use this hook when you activated ‘Show approx. amount’ option in the plugin settings and you want to change default text on the cart/checkout page generated by this feature ‘(Approx. %s)’ to smth another. Example:
| add_filter('woocs_get_approximate_amount_text', 'my_woocs_get_approximate_amount_text', 999, 2); function my_woocs_get_approximate_amount_text($text, $wc_price) { return sprintf(__('(My Approx. %s)'), $wc_price); } |
$text (string) $wc_price (string) ‘Show approx. amount’ – Show approximate amount on the checkout and the cart page with currency of… read more
Use this hook if you want to add any additional information text after a product price on the shop/category page. Example:
| add_filter('woocs_price_html_tail', function($price_html) { return $price_html . "<strong>Hello World!</strong>"; }); |
Combine it with CSS (in style.css) code if necessary:
| .woocs_price_html_tail{ display: none; } body.single-product .woocs_price_html_tail{ display: block; } body.single-product .related .woocs_price_html_tail{ display: none; } |
This hook uses in index.php of the plugin -> public function woocommerce_price_format:
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 | public function woocommerce_price_format() { $currencies = $this->get_currencies(); $currency_pos = 'left'; if (isset($currencies[$this->current_currency])) { $currency_pos = $currencies[$this->current_currency]['position']; } $format = '%1$s%2$s'; switch ($currency_pos) { case 'left' : $format = '%1$s%2$s'; break; case 'right' : $format = '%2$s%1$s'; break; case 'left_space' : $format = '%1$s %2$s'; break; case 'right_space' : $format = '%2$s %1$s'; break; } return apply_filters('woocs_price_format', $format, $currency_pos); } |
So if you have any idea about your own price format use this hook with/without any conditions by your own logic:
| add_filter('woocs_price_format', 'my_woocs_custom_format', 999, 2); function my_woocs_custom_format($format, $currency_pos) { //do smth with $format here return $format; } |