Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
December 13, 2022 at 11:24 pm #1376096
Hello there,
I’ve come across a PHP Snippet that I am trying to incorporate in my child theme’s functions.php file. My goal is to hide the following section when the user selects the Local Pickup option when checking out:
This is the link to the code that I found, and I’ve attached the code to this post as well.
/** * @snippet Hide Shipping Fields for Local Pickup * @how-to Get CustomizeWoo.com FREE * @sourcecode https://businessbloomer.com/?p=72660 * @author Rodolfo Melogli * @testedwith WooCommerce 3.5.7 * @donate $9 https://businessbloomer.com/bloomer-armada/ */ add_action( 'woocommerce_after_checkout_form', 'bbloomer_disable_shipping_local_pickup' ); function bbloomer_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('#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('#customer_details .col-2').fadeOut(); } else { jQuery('#customer_details .col-2').fadeIn(); } }); </script> <?php }
I’m assuming that
'#customer_details .col-2'
from the included PHP snippet above needs to be changed to something likewoocommerce-shipping-destination
and"woocommerce-shipping-calculator"
Any help is appreciated, thanks very much!
December 16, 2022 at 3:19 am #1376324Hi sdsitetechdotcom,
Yes you are correct, please change ‘#customer_details .col-2’ in the code to ‘.woocommerce-shipping-destination, .woocommerce-shipping-calculator’
Hope it helps.Best regards,
Nikko -
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.