61
Let’s talk about checkout UX: if a user is willing to pick up the item in store, why should there be a shipping form on the checkout?
Well, let’s see how we can hide this dynamically with a bit of PHP and JS!
PHP Snippet: Hide Shipping Fields When Local Pickup is Selected – WooCommerce Checkout
/**
* @snippet Hide Shipping Fields for Local Pickup
* @how-to Get tutoraspire.com FREE
* @sourcecode https://tutoraspire.com/?p=72660
* @author Tutor Aspire
* @testedwith WooCommerce 3.5.7
* @donate $9 https://tutoraspire.com
*/
add_action( 'woocommerce_after_checkout_form', 'tutoraspire_disable_shipping_local_pickup' );
function tutoraspire_disable_shipping_local_pickup( $available_gateways ) {
// Part 1: Hide shipping based on the static choice @ Cart
// Note: "#customer_details .col-2" strictly depends on your theme
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ( 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
?>