Skip to content

Instantly share code, notes, and snippets.

@praveencs87
Created November 26, 2020 08:35
Show Gist options
  • Save praveencs87/0b837ddb3b2932317c3b4f8e27cd700c to your computer and use it in GitHub Desktop.
Save praveencs87/0b837ddb3b2932317c3b4f8e27cd700c to your computer and use it in GitHub Desktop.
Hide Shipping Section in checkout page when local pickup is selected - woocommerce | webinwordpress.com
<?php
add_action( 'woocommerce_after_checkout_form', 'webinwp_hide_shipping' );
// Disable Shipping form section in Checkout page
function webinwp_hide_shipping( $available_gateways ) {
// NB: "#customer_details .col-2" based on your theme html attributes
$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('#customer_details .col-2').fadeOut();
</script>
<?php
}
// NB: "#customer_details .col-2" based on your theme html attributes
?>
<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('#customer_details .col-2').fadeOut();
} else {
jQuery('#customer_details .col-2').fadeIn();
}
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment