Disable checkout if no shipping method is available

[ad_1]

Hi @preetindersodhi

How to fix this issue?

As with most custom business cases, you can use the provided filters from WooCommerce to achieve the desired functionality.

If you want to hide PayPal as a payment option if there are no shipping methods then you can add some simple PHP that filters it based on the shipping method availability.

Example:

add_filter('woocommerce_available_payment_gateways', function($gateways){
	if(is_checkout()){
		$packages = WC()->shipping()->get_packages();
		$has_methods = array_reduce($packages, function($has_methods, $package){
			if(!$has_methods){
				return !empty($package['rates']);
			}
			return $has_methods;
		}, false);
		if(!$has_methods){
			unset($gateways['ppcp']);
		}
	}
	return $gateways;
});

Kind Regards

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer