Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ajboni
Created May 3, 2020 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajboni/8fcfb17ad75f70f7522978bd27f8ed04 to your computer and use it in GitHub Desktop.
Save ajboni/8fcfb17ad75f70f7522978bd27f8ed04 to your computer and use it in GitHub Desktop.
Wordpress / Woocommerce - Hide Shipping Fields and address selector for Local Pickup in Cart Page
/**
* @snippet Hide Shipping Fields and address selector for Local Pickup in Cart Page
* @author Alexis Boni
* @testedwith WooCommerce 5.4 - OceanWP theme.
*/
do_action('woocommerce_after_shipping_rate', $method, $index);
// define the woocommerce_after_shipping_rate callback
function action_woocommerce_after_shipping_rate($method, $index)
{
// make action magic happen here...
?>
<script type="text/javascript">
jQuery(document).ready(function($){
// Class names might change depending on your theme.
var val = jQuery("input[name='shipping_method[0]']:checked").val()
if (val.match("^local_pickup")) {
jQuery('.woocommerce-shipping-destination, .woocommerce-shipping-calculator').fadeOut();
} else {
jQuery('.woocommerce-shipping-destination, .woocommerce-shipping-calculator').fadeIn();
}
});
</script>
<?php
};
// add the action
add_action('woocommerce_after_shipping_rate', 'action_woocommerce_after_shipping_rate', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment