Last active
November 5, 2017 05:31
-
-
Save clintN/798e6f7b6388e690fd991e345585ecf6 to your computer and use it in GitHub Desktop.
Hides shipping if Local Pickup selected in flatsome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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