mercredi 2 décembre 2020

Change value of shipping city field if checkbox is checked on WooCommerce checkout page

I am trying to set a value "local-pickup" for the shipping city filed if a checkbox is checked, also to hide the filed when the checkbox is set.

I was able to hide the field but was unable to change the value of the filed to "local-pickup" when the checkbox is checked. the field shipping city is a select field.

this is my code:

add_action('woocommerce_after_checkout_form', 'bbloomer_conditionally_hide_show_checkout_field', 9999);

function bbloomer_conditionally_hide_show_checkout_field() {
  wc_enqueue_js("
    jQuery('#shipping_checkbox').change(function() {
      if (this.checked) {
        jQuery('#shipping_address_1_field').hide();
        jQuery('#shipping_address_2_field').hide();
        jQuery('#shipping_city_field').hide();
      } else {
        jQuery('#shipping_address_1_field').show();
        jQuery('#shipping_address_2_field').show();
        jQuery('#shipping_city_field').show();
      }
    }).keyup();
    ");
  }

thanks




Aucun commentaire:

Enregistrer un commentaire