Nathan Otten
Nathan Otten

Reputation: 21

Set WooCommerce billing country based on WPML current language

I am using the following code to change WooCommerce billing country to the selected site language.

add_filter('init', function() {
    
    $lang = apply_filters( 'wpml_current_language', NULL );
    $lang = strtoupper($lang);
    
    WC()->customer->set_country( $lang );

});

The code is working, but only when the cart or checkout page is loaded. What I am trying to achieve is that the billing country is changed on the first page the customer lands on, so not just on the cart or checkout page.

Tax and currency are calculated based on the billing country. So I want these two to change with it when the customer selects a different language.

Does anyone know how I can achieve this?

Upvotes: 2

Views: 66

Answers (0)

Related Questions