businessdad icon

WooCommerce Memberships - Fix double discount

businessdad | PRO | 05/06/20 12:06:57 PM UTC | 0 ⭐ | 919 👁️ | Never ⏰ | []
PHP |

2.44 KB

|

None

|

0 👍

/

0 👎

/**
 * WooCommerce Memberships - Fix double discount issue
 * The following code snippet aims to fix the issue of discounts being applied twice by the WooCommerce
 * Memberships plugin when the Aelia Currency Switcher is active.
 * 
 * IMPORTANT
 * This code should only be used when the Aelia Currency Switcher is active. Please remember to disable
 * or remove it if you deactivate or uninstall our plugin.
 *
 * 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
 */
add_action('wc_memberships_discounts_enable_price_adjustments', function() {
  // Fetch the instance of the discount calculator used by the Memberships plugin
  $wcm_discounts = wc_memberships()->get_member_discounts_instance();
 
  // Fetch the priority used by the filters of the Memberships plugin
  $priority = apply_filters('wc_memberships_price_adjustments_filter_priority', 999);
 
  // Remove the filters used by the Memberships plugin to calculate the variation
  // prices for the price range of variable products. Those filters are not
  // needed when the Aelia Currency Switcher is active. The multi-currency price 
  // calculation triggers the processing of Memberships discounts while converting 
  // the variations' base prices.
  remove_filter('woocommerce_variation_prices_sale_price', array($wcm_discounts, 'get_member_variation_price' ), $priority, 3 );
  remove_filter('woocommerce_variation_prices_price', array($wcm_discounts, 'get_member_variation_price' ), $priority, 3 );
  remove_filter('woocommerce_variation_prices_regular_price', array($wcm_discounts, 'get_member_variation_regular_price' ), $priority, 3 );
}, 99);

Comments