Hide shipping calculator for Local pickup in WooCommerce

/**
 * Hides shipping calculator from the cart page when "Local pickup" is selected.
 *
 * @see https://wpcodebook.com/woocommerce-hide-shipping-calculator-local-pickup/
 * @see https://github.com/woocommerce/woocommerce/blob/9.3.3/plugins/woocommerce/includes/wc-cart-functions.php#L253
 */
add_filter( 'woocommerce_shipping_show_shipping_calculator', function ( $first, $i, $package ) {
	if (
		$first &&
		! empty( WC()->session->chosen_shipping_methods )
	) {
		foreach ( WC()->session->chosen_shipping_methods as $chosen_shipping_method ) {
			$chosen_shipping_method = explode( ':', $chosen_shipping_method );
			if ( 'local_pickup' === $chosen_shipping_method[0] ) {
				return false;
			}
		}
	}
	return $first;
}, PHP_INT_MAX, 3 );

Leave a Comment