compatible with WPML on switching the language in cart
compatible with WPML on switching the language in cart
function wpml_language_has_switched_woo_discount_compatible(){
if (is_cart()) {
$wpml_language = '';
if ( defined( 'ICL_LANGUAGE_CODE' ) ) {
$wpml_language = ICL_LANGUAGE_CODE;
}
if(!empty($wpml_language)){
$carts = WC()->cart->get_cart();
foreach ($carts as $cart_item_key => $cart_item) {
$have_to_do = false;
$product_id = $cart_item['data']->get_id();
$lang_code = wpml_element_language_code_filter( null, array('element_id' => $product_id, 'element_type' => 'post'));
if($lang_code == $wpml_language){
$have_to_do = true;
}
}
if(!$have_to_do){
add_action('woocommerce_before_cart', function (){
?>
<script type="text/javascript">
jQuery( document ).ready(function() {
jQuery("[name='update_cart']").removeAttr('disabled');
jQuery("[name='update_cart']").trigger("click");
});
</script>
<?php
});
}
}
}
}
add_action('wpml_language_has_switched', 'wpml_language_has_switched_woo_discount_compatible');