Tax For WooCommerce And WPML

0.0/5
<?php
function my_function_with_wc_functions()
{
    global $woocommerce;
    if (WC()->customer)
    {
        $hasChanged = false;
        if (is_user_logged_in())
        {
            if (!get_user_meta(get_current_user_id() , "snippetlang", true))
            {
                update_user_meta(get_current_user_id() , "snippetlang", strtoupper(apply_filters('wpml_current_language', null)));
                $hasChanged = true;
            }
            else
            {
                if (strtoupper(apply_filters('wpml_current_language', null)) != get_user_meta(get_current_user_id() , "snippetlang", true))
                {
                    update_user_meta(get_current_user_id() , "snippetlang", strtoupper(apply_filters('wpml_current_language', null)));
                    $hasChanged = true;
                }
            }
        }
        if ($hasChanged)
        {
            $woocommerce
                ->customer
                ->set_billing_country(strtoupper(apply_filters('wpml_current_language', null)));
            $woocommerce
                ->customer
                ->set_shipping_country(strtoupper(apply_filters('wpml_current_language', null)));

        }
    }

    function default_location_override($location)
    {
        global $sitepress;
        $location['country'] = strtoupper(apply_filters('wpml_current_language', null));
        return $location;
    }

    add_filter('woocommerce_customer_default_location_array', 'default_location_override', 9999, 1);
    add_filter('default_checkout_billing_country', 'change_default_checkout_country');
    add_filter('default_checkout_shipping_country', 'change_default_checkout_country');
    function change_default_checkout_country($default)
    {
        return strtoupper(apply_filters('wpml_current_language', null));
    }
}
add_action('wp_loaded', 'my_function_with_wc_functions');

Comments and reviews

{{ reviewsTotal }} Review
{{ reviewsTotal }} Reviews
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}

Description

This snippet was fetched automatically from WPDistro.cz projects.

Author

Tags

This snippet is untagged