Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How To Disable Shipping Method If User Is Logged Out in WooCommerce?

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? - Tyche Softwares

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? - Tyche Softwares

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?

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Newest
Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x