Advertisement
businessdad

Flycart Woo Discount Rules - Basic Integration

Sep 11th, 2019
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.06 KB | None | 0 0
  1. /**
  2.  * Basic integration between WooCommerce Discount Rules, by FlyCart, and
  3.  * WooCommerce Currency Switcher,  by Aelia (https://aelia.co).
  4.  * DISCLAIMER
  5.  * Aelia and any member of its staff are not responsible for any data loss or damage incurred
  6.  * when using the code, which you can use at your own risk.
  7.  *
  8.  * GPL DISCLAIMER
  9.  * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  10.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  11.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  12.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  13.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  14.  *
  15.  * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
  16.  */  
  17.  
  18. /**
  19.  * Intercepts the discount set by the WooCommerce Discount Rules plugin and passes them
  20.  * to the conversion functions.
  21.  *
  22.  * NOTES
  23.  * This filter assumes that the price passed to it is always in shop's base currency, and
  24.  * that function get_woocommerce_currency() always returns the correct active currency (i.e.
  25.  * that other plugins DON'T change the currency returned by the Aelia Currency Switcher).
  26.  *
  27.  * @param float price
  28.  * @param WC_Product product
  29.  * @param WC_Cart cart
  30.  * @return string|float
  31.  */
  32. add_filter('woo_discount_rules_before_apply_discount', function($price, $product, $cart) {
  33.   if(is_numeric($price) && !empty($price)) {
  34.     // Get the source currency. We assume that it's always shop's base currency
  35.     $from_currency = get_option('woocommerce_currency');
  36.     // Pass the price to the currency conversion filter provided by the Currency Switcher. This
  37.     $price = apply_filters('wc_aelia_cs_convert', $price, $from_currency, get_woocommerce_currency());
  38.   }
  39.  
  40.   return $price;
  41. }, 10, 3);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement