Last active
October 11, 2019 11:20
-
-
Save AshlinRejo/18060f672fce90b1af6464138f219e63 to your computer and use it in GitHub Desktop.
Woo Discount Rules: Compatible for Multi Currency for WooCommerce by villaTheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!function_exists('woo_discount_rules_compatible_with_villa_theme_currency_switcher')){ | |
function woo_discount_rules_compatible_with_villa_theme_currency_switcher($price, $is_cart = false, $discount_type = 'percentage_discount'){ | |
$process_conversion = true; | |
if($is_cart === true){ | |
if($discount_type !== 'percentage_discount'){ | |
$process_conversion = false; | |
} | |
} | |
if($process_conversion){ | |
$class_exists = false; | |
if(class_exists('WOOMULTI_CURRENCY_F_Data')){ | |
$setting = new WOOMULTI_CURRENCY_F_Data(); | |
$class_exists = true; | |
} elseif(class_exists('WOOMULTI_CURRENCY_Data')){ | |
$setting = new WOOMULTI_CURRENCY_Data(); | |
$class_exists = true; | |
} | |
if($class_exists === true){ | |
$selected_currencies = $setting->get_list_currencies(); | |
$current_currency = $setting->get_current_currency(); | |
if ( ! $current_currency ) { | |
return $price; | |
} | |
if ( $price ) { | |
$price = $price / $selected_currencies[ $current_currency ]['rate']; | |
} | |
} | |
} | |
return $price; | |
} | |
} | |
add_filter('woo_discount_rules_before_apply_discount', function ($price, $product, $cart){ | |
return woo_discount_rules_compatible_with_villa_theme_currency_switcher($price); | |
}, 10, 3); | |
add_filter('woo_discount_rules_before_calculate_discount_from_subtotal_in_cart', function ($subtotal, $discount_type, $rule){ | |
return woo_discount_rules_compatible_with_villa_theme_currency_switcher($subtotal, true, $discount_type); | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment