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.
In another scenario, if the customer is already logged in, then the “free shipping” method is shown, as illustrated below.
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?