businessdad

WooCommerce Memberships - Fix double discount

May 6th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * WooCommerce Memberships - Fix double discount issue
  3.  * The following code snippet aims to fix the issue of discounts being applied twice by the WooCommerce
  4.  * Memberships plugin when the Aelia Currency Switcher is active.
  5.  *
  6.  * IMPORTANT
  7.  * This code should only be used when the Aelia Currency Switcher is active. Please remember to disable
  8.  * or remove it if you deactivate or uninstall our plugin.
  9.  *
  10.  * DISCLAIMER
  11.  * Aelia and any member of its staff are not responsible for any data loss or damage incurred
  12.  * when using the code, which you can use at your own risk.
  13.  *
  14.  * GPL DISCLAIMER
  15.  * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
  16.  * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
  17.  * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
  18.  * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
  19.  * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
  20.  *
  21.  * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
  22.  */
  23. add_action('wc_memberships_discounts_enable_price_adjustments', function() {
  24.   // Fetch the instance of the discount calculator used by the Memberships plugin
  25.   $wcm_discounts = wc_memberships()->get_member_discounts_instance();
  26.  
  27.   // Fetch the priority used by the filters of the Memberships plugin
  28.   $priority = apply_filters('wc_memberships_price_adjustments_filter_priority', 999);
  29.  
  30.   // Remove the filters used by the Memberships plugin to calculate the variation
  31.   // prices for the price range of variable products. Those filters are not
  32.   // needed when the Aelia Currency Switcher is active. The multi-currency price
  33.   // calculation triggers the processing of Memberships discounts while converting
  34.   // the variations' base prices.
  35.   remove_filter('woocommerce_variation_prices_sale_price', array($wcm_discounts, 'get_member_variation_price' ), $priority, 3 );
  36.   remove_filter('woocommerce_variation_prices_price', array($wcm_discounts, 'get_member_variation_price' ), $priority, 3 );
  37.   remove_filter('woocommerce_variation_prices_regular_price', array($wcm_discounts, 'get_member_variation_regular_price' ), $priority, 3 );
  38. }, 99);
Add Comment
Please, Sign In to add comment