AI Verified

Name

Hide users Address if Local Pickup is not selected (PHP version)

About

This is to “Hide the user's Address if Local Pickup is not selected” I'm using the plugin “WooCommerce Advanced Shipping” by “Jeroen Sormani”, but it doesn't seem to matter. It's currently working with the default “store pickup” as well. The original code did not have the array. It could be my set-up, I'm not sure. Give a go and see what happens. There is also a CSS combination to display a unique address, if the other options are selected. https://codesnippets.cloud/snippet/Unkillhank/CSS-version

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

Copy the code, into your awesome snippets tool ;) Use the PHP option and save. Change the ID's to yours. Look for '555', '97838', '709279', '97676'. The numbers in the array are all my ID's from the “WooCommerce Advanced Shipping” tool. Yours will be different. (WordPress ID's, not CSS ID's) P.S. The optional CSS is using the matching CSS IDs, and they happen to be the same numbers, so heads up. https://codesnippets.cloud/snippet/Unkillhank/CSS-version

Codevault

Unkillhank

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Snippet Source:

https://wordpress.org/support/topic/in-cart-hide-shipping-to-when-local-pickup-selected/

History

Last modified:

22/01/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Hide users Address if Local Pickup is not selected (PHP version)

 
                    
1// **The css optional code for this functoin
2// https://codesnippets.cloud/snippet/Unkillhank/CSS-version
3 
4 
5add_action( 'woocommerce_before_cart', 'remove_shipping_to_cart_local' );
6 
7function remove_shipping_to_cart_local() {
8 // part 1: check on page load and hide if local pickup
9 $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
10 $chosen_shipping = $chosen_methods[0];
11 $local_pickup_methods = array( '555', '97838', '709279', '97676' );
12 if ( in_array( $chosen_shipping, $local_pickup_methods ) ) {
13 ?>
14 <script type="text/javascript">
15 jQuery(document).ready(function () {
16 jQuery('p.woocommerce-shipping-destination').css("display", "none");
17 });
18 </script>
19 <?php
20 }
21 ?>
22 <script type="text/javascript">
23 jQuery('form.woocommerce-cart-form').on('change', 'input[name^="shipping_method"]', function () {
24 var val = jQuery('input[name^="shipping_method"]:checked').val();
25 var local_pickup_methods = ['555', '97838', '709279', '97676'];
26 if (local_pickup_methods.includes(val)) {
27 jQuery('p.woocommerce-shipping-destination').css("display", "none");
28 } else {
29 jQuery('p.woocommerce-shipping-destination').css("display", "block");
30 }
31 });
32 
33 jQuery(document).ajaxComplete(function () {
34 if (jQuery('input[name^="shipping_method"]').attr('type') === 'hidden') {
35 var val = jQuery('input[name^="shipping_method"]').val();
36 } else {
37 var val = jQuery('input[name^="shipping_method"]:checked').val();
38 }
39 var local_pickup_methods = ['555', '97838', '709279', '97676'];
40 if (local_pickup_methods.includes(val)) {
41 jQuery('p.woocommerce-shipping-destination').css("display", "none");
42 } else {
43 jQuery('p.woocommerce-shipping-destination').css("display", "block");
44 }
45 });
46 </script>
47 <?php
48}

0

Comments

  • M
    Max

    1 year ago

    I love this snippet! Commenting on my snippet is no different than you taking selfies, LOL eat it!

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

1

WooCommerce Disable Payment Gateway Based On Shipping Method

Added: 1 year ago

Last Updated: 2 months ago

If you do not have the facility to take payments other than cash for in-person shipping methods like local pickup, you may wish to disable the appropriate payment gateways and force the customer to pa...

WooCommerce

AI Verified

0

WooCommerce Product Price Display with Offer Validity

Added: 9 months ago

Last Updated: 9 months ago

How long is the discounted price of one of your products valid? This code checks if the product is being viewed on a single page and has a sale end date. If true, it adds a message indicating the offe...

WooCommerce

Unverified

0

Hide if Local Pickup is not selected, change Address (CSS version)

Added: 1 year ago

Last Updated: 1 year ago

This CSS should be used with the: https://codesnippets.cloud/snippet/Unkillhank/Hide-users-Address-if-Local-Pickup-is-not-selected-(PHP-version) This is the CSS combination to display a unique add...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

0

Hide users Address if Local Pickup is not selected (PHP version)

Added: 1 year ago

Last Updated: 1 year ago

This is to “Hide the user's Address if Local Pickup is not selected” I'm using the plugin “WooCommerce Advanced Shipping” by “Jeroen Sormani”, but it doesn't seem to matter. It's currently working wit...

WooCommerce

Unverified

0

Hide if Local Pickup is not selected, change Address (CSS version)

Added: 1 year ago

Last Updated: 1 year ago

This CSS should be used with the: https://codesnippets.cloud/snippet/Unkillhank/Hide-users-Address-if-Local-Pickup-is-not-selected-(PHP-version) This is the CSS combination to display a unique add...