Skip to content

Instantly share code, notes, and snippets.

@clintN
Last active November 5, 2017 05:31
Show Gist options
  • Select an option

  • Save clintN/798e6f7b6388e690fd991e345585ecf6 to your computer and use it in GitHub Desktop.

Select an option

Save clintN/798e6f7b6388e690fd991e345585ecf6 to your computer and use it in GitHub Desktop.
Hides shipping if Local Pickup selected in flatsome
add_action( 'woocommerce_after_checkout_form', 'bbloomer_disable_shipping_local_pickup' );
function bbloomer_disable_shipping_local_pickup( $available_gateways ) {
global $woocommerce;
// Part 1: Hide shipping based on the static choice @ Cart
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping_no_ajax = $chosen_methods[0];
if ( 0 === strpos( $chosen_shipping_no_ajax, 'local_pickup' ) ) {
?>
<script type="text/javascript">
jQuery('#customer_details .woocommerce-shipping-fields').fadeOut();
</script>
<?php
}
// Part 2: Hide shipping based on the dynamic choice @ Checkout
?>
<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 .woocommerce-shipping-fields').fadeIn();
}
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment