Home > database >  Hide country at checkout when not a Wholesale Customer?
Hide country at checkout when not a Wholesale Customer?

Time:09-29

I am looking to add a php code in functions for the following question? (woocommerce) I want to hide a few countries (Germany, Denmark) at the checkout page when you are not logged in as a wholesale customer?

CodePudding user response:

By using woocommerce_countries filter you can do it like this

function wholesale_country_restrictions( $country) {
    $user = wp_get_current_user();
    // Change administrator with your user role
    if( isset( $user->roles[0] ) && $user->roles[0] == 'administrator') {
        unset($country["DE"]);
        unset($country["DK"]);
        return $country; 
    }
}
add_filter( 'woocommerce_countries', 'wholesale_country_restrictions', 10, 1 );

Add the code in your functions.php file in your active parent/child theme

CodePudding user response:

Coding appears to not be working as my site gives "A critical error has occurred on this"

  • Related