Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Balakrishnan-flycart/a2d0eb8f2149501660afbbc9d243bb9e to your computer and use it in GitHub Desktop.
Save Balakrishnan-flycart/a2d0eb8f2149501660afbbc9d243bb9e to your computer and use it in GitHub Desktop.
Woo Discount Rules v2 - Wpml Multi Currency Compatible for Variable Products
add_filter('advanced_woo_discount_rules_get_price', function($price, $product){
$current_currency = apply_filters('wcml_price_currency', NULL );
if (method_exists($product, 'get_id')) {
$product_id = $product->get_id();
}
if (method_exists($product, 'is_type') && !empty($current_currency)) {
$is_variable_product = $product->is_type('variable');
if($is_variable_product){
if (method_exists($product, 'get_available_variations') && method_exists($product, 'get_variation_default_attribute')) {
$available_variations = $product->get_available_variations();
if(!empty($available_variations)){
foreach($available_variations as $variation_values ){
$is_default_variation = false;
foreach($variation_values['attributes'] as $key => $attribute_value ){
$attribute_name = str_replace( 'attribute_', '', $key );
$default_value = $product->get_variation_default_attribute($attribute_name);
if(!empty($default_value)){
if( $default_value == $attribute_value ){
$is_default_variation = true;
} else {
$is_default_variation = false;
break;
}
}
}
if( $is_default_variation ){
$variation_id = $variation_values['variation_id'];
break;
}
}
if(!isset($variation_id)){
if (method_exists($product, 'get_children')) {
$children_ids = $product->get_children();
$variation_id = reset($children_ids);
}
}
}
}
if(isset($variation_id) && !empty($variation_id)){
$product_id = $variation_id;
}
$price = apply_filters( 'wcml_product_price_by_currency', $product_id, $current_currency );
}
}
return $price;
},10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment