skip to Main Content

I want to change this WC()->customer->get_shipping_country(); with a function in my child theme. So when user check the cart, the shipping calculator show options just for CL country.

2

Answers


  1. Chosen as BEST ANSWER

    I found a simple solution. Set the country and shipping country at the moment to add to cart.

    add_action('woocommerce_add_to_cart' , 'set_country_befor_cart_page'); 
    
    function set_country_befor_cart_page(){
        WC()->customer->set_country('CL'); // CL is to set country code of default country
        WC()->customer->set_shipping_country('CL'); //CL is to set country code of default country
    }
    

  2. use

    WC()->customer->shipping_country
    

    instead of

    WC()->customer->get_shipping_country()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search