• Resolved urka

    (@urka)


    Hello,
    please I need help to unset a shipping country with function.php because some countries I am only allowed to ship if logged in user is id 123 or some else of rules.

    For example without any if question I will unset BG and RO:

    function distributor_shippingarea( $fields ) {
    unset($fields[‘shipping’][‘shipping_country’][‘BG’]);
    unset($fields[‘shipping’][‘shipping_country’][‘RO’]);
    return $fields;
    }
    add_filter( ‘woocommerce_checkout_fields’ , ‘distributor_shippingarea’ );

    I get no error but it do not work also. I have in my dropdown fields of the shipping country Romania and Bulgaria to select.

    Please where is my mistake?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Caleb Burks

    (@icaleb)

    Automattic Happiness Engineer

    Not so sure you can do this what that filter. If you can’t get the code needed, I would recommend using a plugin. Conditional Shipping and Payments can help with this: https://www.woocommerce.com/products/woocommerce-conditional-shipping-and-payments/

    Here is a example rule: https://cld.wthms.co/NIfaA5

    Thread Starter urka

    (@urka)

    Hi thx, but after sleepless nights with this problem I got today the issue from a German Programmer.

    Maybe some will need it too, here is the code which works in Woocommerce 3.2.6

    // unset shipping RO BG
    function distributor_countryarea( $countries ) {
    $user = wp_get_current_user();
    if ( $user->ID != ‘123’ ) {
    unset( $countries[‘BG’] );
    unset( $countries[‘RO’] );
    }

    return $countries;
    }
    add_filter( ‘woocommerce_countries_shipping_countries’, ‘distributor_countryarea’, 10, 1 );

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘unset shipping country in function.php’ is closed to new replies.