Enabling or disabling shipping options based on whether users are logged into their accounts is a straightforward way to encourage account creation in your store. By implementing a code snippet, you can offer exclusive benefits like free shipping to users who are logged in.
add_filter( 'woocommerce_package_rates', 'ts_disable_shipping_method_based_on_login_status', 10, 2 ); function ts_disable_shipping_method_based_on_login_status($rates, $package) { if (!is_user_logged_in()) { unset( $rates['free_shipping:1'] ); // The shipping method radio button value } return $rates; }
Output
When the customer logs out, the shipping method (i.e., free shipping) is hidden from the cart page, as shown below.
![How To Disable Shipping Method If User Is Logged Out in WooCommerce? 1 How To Disable Shipping Method If User Is Logged Out in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/WooCommerce-Disable-Shipping-Method-Based-on-User-Log-out-1024x726.png)
In another scenario, if the customer is already logged in, then the “free shipping” method is shown, as illustrated below.
![How To Disable Shipping Method If User Is Logged Out in WooCommerce? 2 How To Disable Shipping Method If User Is Logged Out in WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/WooCommerce-Default-Shipping-Method-in-Checkout-Page.png)
Alternatively, you can dynamically hide shipping methods based on user roles in WooCommerce which will help to hide free shipping method for certain user roles.
Read Related Article: How to Customize Selected Shipping Method’s Title in WooCommerce Cart?