Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Basic integration between WooCommerce Discount Rules, by FlyCart, and
- * WooCommerce Currency Switcher, by Aelia (https://aelia.co).
- * DISCLAIMER
- * Aelia and any member of its staff are not responsible for any data loss or damage incurred
- * when using the code, which you can use at your own risk.
- *
- * GPL DISCLAIMER
- * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
- * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
- * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
- * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
- * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
- *
- * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
- */
- /**
- * Intercepts the discount set by the WooCommerce Discount Rules plugin and passes them
- * to the conversion functions.
- *
- * NOTES
- * This filter assumes that the price passed to it is always in shop's base currency, and
- * that function get_woocommerce_currency() always returns the correct active currency (i.e.
- * that other plugins DON'T change the currency returned by the Aelia Currency Switcher).
- *
- * @param float price
- * @param WC_Product product
- * @param WC_Cart cart
- * @return string|float
- */
- add_filter('woo_discount_rules_before_apply_discount', function($price, $product, $cart) {
- if(is_numeric($price) && !empty($price)) {
- // Get the source currency. We assume that it's always shop's base currency
- $from_currency = get_option('woocommerce_currency');
- // Pass the price to the currency conversion filter provided by the Currency Switcher. This
- $price = apply_filters('wc_aelia_cs_convert', $price, $from_currency, get_woocommerce_currency());
- }
- return $price;
- }, 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement