Easy methods to Cover Woocommerce Checkout Fields When Native Pickup is Chosen?

Most annoying factor with the Woocommerce Native Pickup delivery technique is that though no delivery info is required, you continue to must fill in all of the handle and postcode fields. However what in case you might robotically conceal these fields if the native pickup technique is chosen? Properly, check out this video under, after which you’ll be able to.

Video: Easy methods to Cover Woocommerce Checkout Fields When Native Pickup is Chosen?

Code snippet used within the video

/* This piece of code will conceal fields for the chosen technique.
.hide_pickup {
    show: none !vital;
}
*/
 
// Cover Native Pickup delivery technique
add_filter( 'woocommerce_checkout_fields', 'hide_local_pickup_method' );
perform hide_local_pickup_method( $fields_pickup ) {
    // change under for the tactic
    $shipping_method_pickup ='local_pickup:4';
    // change under for the listing of fields. Add (or delete) the sphere title you need (or don’t need) to make use of
    $hide_fields_pickup = array( 'billing_company', 'billing_country', 'billing_postcode', 'billing_address_1', 'billing_address_2' , 'billing_city', 'billing_state');
 
    $chosen_methods_pickup = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping_pickup = $chosen_methods_pickup[0];
 
    foreach($hide_fields_pickup as $field_pickup ) {
        if ($chosen_shipping_pickup == $shipping_method_pickup) {
            $fields_pickup['billing'][$field_pickup]['required'] = false;
            $fields_pickup['billing'][$field_pickup]['class'][] = 'hide_pickup';
        }
        $fields_pickup['billing'][$field_pickup]['class'][] = 'billing-dynamic_pickup';
    }
    return $fields_pickup;
}
// Native Pickup - conceal fields
add_action( 'wp_head', 'local_pickup_fields', 999 );
perform local_pickup_fields() {
    if (is_checkout()) :
    ?>
    <type>
        .hide_pickup {show: none!vital;}
    </type>
    <script>
        jQuery( perform( $ ) {
            if ( typeof woocommerce_params === 'undefined' ) {
                return false;
            }
            $(doc).on( 'change', '#shipping_method enter[type="radio"]', perform() {
                // change local_pickup:4 accordingly
            $('.billing-dynamic_pickup').toggleClass('hide_pickup', this.worth == 'local_pickup:4');
            });
        });
    </script>
    <?php
    endif;
}

Easy methods to conceal Woocommerce delivery handle part if Native pickup is chosen?

Properly, it looks like an inexpensive want to conceal whole Woocommerce delivery handle part if native pickup is chosen. Which means the “Ship to completely different handle” choose field can be hidden in case you use this snippet right here under.

add_action( 'woocommerce_after_checkout_form', 'hide_ship_to_section' );
  
perform <meta charset="utf-8">hide_ship_to_section( $available_gateways ) {
    
   $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
   $chosen_shipping = $chosen_methods[0];
   if ( 0 === strpos( $chosen_shipping, 'local_pickup' ) ) {
   ?>
      <script kind="textual content/javascript">
         jQuery('#customer_details .col-2').fadeOut();
      </script>
   <?php  
   } 
   ?>
      <script kind="textual content/javascript">
         jQuery('kind.checkout').on('change','enter[name^="shipping_method"]',perform() {
            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
  
}

Easy methods to Cover Woocommerce Checkout Fields Based mostly on Transport Strategies?

Now, if you want to cover Woocommerce checkout fields for a number of chosen delivery strategies, then it’s a bit trickier. There are couple of issues I must level out for this code right here under.

So, this snippet right here under does this:

  • If Native pickup (local_pickup:2) is chosen, Billing nation, postcode, handle 1, handle 2 and metropolis fields are disabled.
  • If Native Pickup 2 (local_pickup:8) is chosen, Billing nation, postcode, handle 1, handle 2 and metropolis fields are disabled.
  • If Native pickup (multiparcels_smartpost_pickup_point:7) is chosen, Billing nation, postcode, handle 1, handle 2 and metropolis and cellphone fields are disabled.

If you need to make use of this snippet, then check out line 30 for altering your delivery ID. Line 33 comprises fields to be hidden. And line 70 ought to as soon as once more comprises your delivery technique. So, the whole lot between strains 25 and 76 comprises code for Native pickup technique. Strains 78-130 is used for Native pickup 2 and features 132-182 are for SmartPost delivery technique.

In an analogous manner you’ll be able to add (or take away) your personal extra delivery strategies.

/* CSS courses for hiding fields
.hide_local {
    show: none !vital;
}
.hide_local2 {
    show: none !vital;
}
.hide_smartpost {
    show: none !vital;
}

AVAILABLE BILLING FIELDS
billing_company = COMPANY
billing_country = COUNTRY
billing_postcode = POSTCODE
billing_address_1 = ADDRESS 1
billing_address_2 = ADDRESS 2
billing_city = CITY
billing_last_name = LAST NAME
billing_first_name = FIRST NAME
billing_phone = PHONE
*/


// Cover native pickup fields
add_filter( 'woocommerce_checkout_fields', 'wpsh_hide_local_pickup_fields' );
perform wpsh_hide_local_pickup_fields( $fields_itella ) {
    
  // Add your personal delivery technique ID
    $shipping_method_itella ='local_pickup:2'; 
  
    // change under for the listing of fields
    $hide_fields_itella = array( 'billing_company', 'billing_country', 'billing_postcode', 'billing_address_1', 'billing_address_2' , 'billing_city' );

    $chosen_methods_itella = WC()->session->get( 'chosen_shipping_methods' );
    // uncomment under line and reload checkout web page to verify present $chosen_methods
    // print_r($chosen_methods);
    $chosen_shipping_itella = $chosen_methods_itella[0];

    foreach($hide_fields_itella as $field_itella ) {
        if ($chosen_shipping_itella == $shipping_method_itella) {
            $fields_itella['billing'][$field_itella]['required'] = false;
            $fields_itella['billing'][$field_itella]['class'][] = 'hide_local';
        }
        $fields_itella['billing'][$field_itella]['class'][] = 'billing-dynamic_itella';
    }
    return $fields_itella;
}

// Native pickup Ajax

add_action( 'wp_head', 'wpsh_local_pickup_ajax', 999 );
perform wpsh_local_pickup_ajax() {
    if (is_checkout()) :
    ?>
    <type>
        .hide_local {show: none!vital;}
    </type>
    <script>
        jQuery( perform( $ ) {

            // woocommerce_params is required to proceed, guarantee the article exists
            if ( typeof woocommerce_params === 'undefined' ) {
                return false;
            }

            $(doc).on( 'change', '#shipping_method enter[type="radio"]', perform() {
			  
               // Add your personal delivery technique ID
            $('.billing-dynamic_itella').toggleClass('hide_local', this.worth == 'local_pickup:2');  
            });
        });
    </script>
    <?php
    endif;
}

// // Cover native pickup 2 fields

add_filter( 'woocommerce_checkout_fields', 'wpsh_hide_local_pickup2_fields' );
perform wpsh_hide_local_pickup2_fields( $fields_omniva ) {
  
// Add your personal delivery technique ID
    $shipping_method_omniva ='local_pickup:8'; 
  
    // change under for the listing of fields
    $hide_fields_omniva = array( 'billing_company', 'billing_country', 'billing_postcode', 'billing_address_1', 'billing_address_2' , 'billing_city' );

    $chosen_methods_omniva = WC()->session->get( 'chosen_shipping_methods' );
    // uncomment under line and reload checkout web page to verify present $chosen_methods
    // print_r($chosen_methods);
    $chosen_shipping_omniva = $chosen_methods_omniva[0];

    foreach($hide_fields_omniva as $field_omniva ) {
        if ($chosen_shipping_omniva == $shipping_method_omniva) {
            $fields_omniva['billing'][$field_omniva]['required'] = false;
            $fields_omniva['billing'][$field_omniva]['class'][] = 'hide_local';
        }
        $fields_omniva['billing'][$field_omniva]['class'][] = 'billing-dynamic_omniva';
    }

    return $fields_omniva;
}

// Native pickup 2 Ajax
add_action( 'wp_head', 'wpsh_hide_local_pickup2_ajax', 999 );
perform wpsh_hide_local_pickup2_ajax() {
    if (is_checkout()) :
    ?>
    <type>
        .hide_local2 {show: none!vital;}
    </type>
    <script>
        jQuery( perform( $ ) {

            // woocommerce_params is required to proceed, guarantee the article exists
            if ( typeof woocommerce_params === 'undefined' ) {
                return false;
            }

            $(doc).on( 'change', '#shipping_method enter[type="radio"]', perform() {
			  
                // Add your personal delivery technique ID
            $('.billing-dynamic_omniva').toggleClass('hide_local2', this.worth == 'local_pickup:8');   
            });
        });
    </script>
    <?php
    endif;
}

// Cover SmartPost fields
add_filter( 'woocommerce_checkout_fields', 'wpsh_hide_smartpost_fields' );
perform wpsh_hide_smartpost_fields( $fields_pickup ) {
  
   // Add your personal delivery technique ID
    $shipping_method_pickup ='multiparcels_smartpost_pickup_point:7'; 
  
    // change under for the listing of fields
    $hide_fields_pickup = array( 'billing_company', 'billing_country', 'billing_postcode', 'billing_address_1', 'billing_address_2' , 'billing_city', 'billing_phone' );

    $chosen_methods_pickup = WC()->session->get( 'chosen_shipping_methods' );
    // uncomment under line and reload checkout web page to verify present $chosen_methods
    // print_r($chosen_methods);
    $chosen_shipping_pickup = $chosen_methods_pickup[0];

    foreach($hide_fields_pickup as $field_pickup ) {
        if ($chosen_shipping_pickup == $shipping_method_pickup) {
            $fields_pickup['billing'][$field_pickup]['required'] = false;
            $fields_pickup['billing'][$field_pickup]['class'][] = 'hide_smartpost';
        }
        $fields_pickup['billing'][$field_pickup]['class'][] = 'billing-dynamic_pickup';
    }

    return $fields_pickup;
}
// Samrtpost Ajax
add_action( 'wp_head', 'wpsh_hide_smartpost_fields_ajax', 999 );
perform wpsh_hide_smartpost_fields_ajax() {
    if (is_checkout()) :
    ?>
    <type>
        .hide_smartpost {show: none!vital;}
    </type>
    <script>
        jQuery( perform( $ ) {

            // woocommerce_params is required to proceed, guarantee the article exists
            if ( typeof woocommerce_params === 'undefined' ) {
                return false;
            }

            $(doc).on( 'change', '#shipping_method enter[type="radio"]', perform() {
			  
               // Add your personal delivery technique ID
            $('.billing-dynamic_pickup').toggleClass('hide_smartpost', this.worth == 'multiparcels_smartpost_pickup_point:7'); 
            });
        });
    </script>
    <?php
    endif;
}

Helpful Ideas

  • Wocommerce: Easy methods to Give a Low cost to Native Pickup?
  • Easy methods to Add Free Transport Notifications (with quantity left) to Woocommerce Product and Cart Pages
  • Easy methods to Present Contact Type Solely When Woocommerce Product is Out Of Inventory?

DON'T MISS NEW ARTICLES

We don’t spam! Read our privacy policy for more info.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
Scroll to Top
Loading...