SHOW:
|
|
- or go back to the newest paste.
| 1 | /** | |
| 2 | - | * WooCommerce Extended Coupon Features |
| 2 | + | * WooCommerce Memberships - Fix double discount issue |
| 3 | - | * The following example shows how to convert the minimum and maximum matching products subtotals |
| 3 | + | * The following code snippet aims to fix the issue of discounts being applied twice by the WooCommerce |
| 4 | - | * assigned to a coupon by using the filters provided by the Aelia Currency Switcher. |
| 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 | - | function convert_amount_from_base_currency($amount, $to_currency) {
|
| 20 | + | |
| 21 | - | if(is_numeric($amount)) {a
|
| 21 | + | |
| 22 | - | $amount = apply_filters('wc_aelia_cs_convert', $amount, get_option('woocommerce_currency'), $to_currency);
|
| 22 | + | |
| 23 | - | } |
| 23 | + | add_action('wc_memberships_discounts_enable_price_adjustments', function() {
|
| 24 | - | return $amount; |
| 24 | + | // Fetch the instance of the discount calculator used by the Memberships plugin |
| 25 | - | } |
| 25 | + | $wcm_discounts = wc_memberships()->get_member_discounts_instance(); |
| 26 | ||
| 27 | - | add_filter('woocommerce_coupon_get__wjecf_min_matching_product_subtotal', function($value, $coupon) {
|
| 27 | + | // Fetch the priority used by the filters of the Memberships plugin |
| 28 | - | $value = convert_amount_from_base_currency($value, get_woocommerce_currency()); |
| 28 | + | $priority = apply_filters('wc_memberships_price_adjustments_filter_priority', 999);
|
| 29 | - | return $value; |
| 29 | + | |
| 30 | - | }, 10, 2); |
| 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 | - | add_filter('woocommerce_coupon_get__wjecf_max_matching_product_subtotal', function($value, $coupon) {
|
| 32 | + | // needed when the Aelia Currency Switcher is active. The multi-currency price |
| 33 | - | $value = convert_amount_from_base_currency($value, get_woocommerce_currency()); |
| 33 | + | // calculation triggers the processing of Memberships discounts while converting |
| 34 | - | return $value; |
| 34 | + | // the variations' base prices. |
| 35 | - | }, 10, 2); |
| 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); |