Checkout

WooCommerce Disable Shipping Method If User Is Logged Out

WooCommerce Disable Shipping Method If User Is Logged Out

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About This Solution

Enabling and disabling shipping method options based on whether the user is logged into their account is easy. Having this code snippet implemented can encourage the user to register an account with your store if it means they get an exclusive shipping option. This guide shows you how you can enable free shipping only for users which are logged in to their account. That means users have have not registered an account and logged in will not see the free shipping option at the checkout. What better incentive to get your users to register with your online store? The only thing you’ll need to tweak in this code is the shipping method radio button value which is explained further in the guide.

/**
 * Snippet Name:	WooCommerce disable shipping method option if user is not logged in. In this example, enable free shipping only if the user is logged in.
 * Snippet Author:	ecommercehints.com
 */

add_filter( 'woocommerce_package_rates', 'ecommercehints_disable_shipping_method_based_on_login_status', 10, 2 );

function ecommercehints_disable_shipping_method_based_on_login_status($rates, $package) {

if (!is_user_logged_in()) {
     unset( $rates['free_shipping:14'] ); // The shipping method radio button value
}
return $rates;
}

How Do I Get The Shipping Method Radio Button Value?

Use your browser’s developer tools (usually F12 on the keyboard) then use the inspect element tool and click on the radio button you’d like to enable/disable. Expand the list until you see the value you’d like. It typically includes a colon and a number as shown in the image.

WooCommerce get shipping method radio button value

Snippet Benefits

  • Encourage your users to register an account with you and reward them with free shipping.
  • Hide shipping methods which are exclusive to those who have registered an account with your online store.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 10% off on your first month with us.

26027
WELCOME OFFER