Hello @luigistefano ,
This is actually a great idea to remove the shipping option when you have selected the Local Pickup option.
I found a code that almost did what you needed. I have modified it to suit your need and work it for both the cart and checkout page. Use this code in your theme’s functions.php file or via code snippet plugin –
add_action( 'woocommerce_after_checkout_form', 'custom_disable_shipping_local_pickup' );
add_action( 'woocommerce_cart_totals_after_shipping', 'custom_disable_shipping_local_pickup' );
function custom_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' ) ) {
?>
<script type="text/javascript">
jQuery('.woocommerce-shipping-destination,.woocommerce-shipping-calculator,#customer_details .col-2').fadeOut();
</script>
<?php
}
// Part 2: Hide shipping based on the dynamic choice @ Checkout
// Note: "#customer_details .col-2" strictly depends on your theme
?>
<script type="text/javascript">
jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() {
var val = jQuery( this ).val();
if (val.match("^local_pickup")) {
jQuery('.woocommerce-shipping-destination,.woocommerce-shipping-calculator,#customer_details .col-2').fadeOut();
} else {
jQuery('.woocommerce-shipping-destination,.woocommerce-shipping-calculator,#customer_details .col-2').fadeIn();
}
});
</script>
<?php
}
I hope this information helps.
Thank you ??