Advertisement
Guest User

Untitled

a guest
Sep 9th, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.81 KB | None | 0 0
  1. wc_hcsa_settings = wc_hcsa_settings || {};
  2.  
  3. jQuery( document ).ready(function() {
  4.     jQuery( '.shipping_address', jQuery( '.woocommerce-shipping-fields' ) ).prevAll().addBack().wrapAll( '<div class="woocommerce-shipping-fields-cnt"></div>' );
  5.     jQuery( 'body' ).trigger( 'updated_checkout_hcsa', ['init'] );
  6. } ).on( 'updated_checkout', 'body',function() {
  7.     jQuery( 'body' ).trigger( 'updated_checkout_hcsa' );
  8. } ).on( 'updated_checkout_hcsa', 'body', function( event, type ) {
  9.     var e = wc_hcsa_settings.effect || 'slide', m = jQuery( 'select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]' ).val(), s, t = jQuery( ' #billing_address_1, #billing_address_2, #billing_state, #billing_city, #billing_postcode, .woocommerce-shipping-fields-cnt' );
  10.     wc_hcsa_settings.fields = wc_hcsa_settings.fields || {};
  11.     wc_hcsa_settings.fields_num = wc_hcsa_settings.fields_num || 0;
  12.  
  13.     if ( type === 'init' ) {
  14.         e = 'none';
  15.     }
  16.  
  17.     if ( t.length && typeof wc_hcsa_settings.methods == 'object' ) {
  18.         s = t.is( ':visible' );
  19.         if ( typeof wc_hcsa_settings.methods[m] == 'undefined' ) {
  20.             wc_hcsa_settings.methods[m] = 'no';
  21.         }
  22.  
  23.         if ( wc_hcsa_settings.methods[m] == 'yes' && s ) {
  24.             t.find( ':input' ).each( function() {
  25.                 var _t = jQuery( this );
  26.                 if ( typeof _t.data( 'hcsaid' ) == 'undefined' ) {
  27.                     _t.data( 'hcsaid', wc_hcsa_settings.fields_num );
  28.                     wc_hcsa_settings.fields_num ++;
  29.                 }
  30.                 if ( _t.is( ':checkbox,:radio' ) ) {
  31.                     wc_hcsa_settings.fields[_t.data( 'hcsaid' )] = _t.is(':checked');
  32.                     _t.prop('checked', false);
  33.                 } else {
  34.                     wc_hcsa_settings.fields[_t.data( 'hcsaid' )] = _t.val();
  35.                     _t.val('');
  36.                 }
  37.             } );
  38.             switch ( e ) {
  39.                 case 'fade':
  40.                     t.fadeOut( function() { t.addClass( 'shipping-fields-hidden' ); } );
  41.                     break;
  42.                 case 'none':
  43.                     t.hide( 0, function() { t.addClass( 'shipping-fields-hidden' ); } );
  44.                     break;
  45.                 default:
  46.                     t.slideUp( function() { t.addClass( 'shipping-fields-hidden' ); } );
  47.             }
  48.         } else if ( wc_hcsa_settings.methods[m] == 'no' && ! s ) {
  49.             t.find( ':input' ).each( function() {
  50.                 var _t = jQuery( this );
  51.                 if ( typeof _t.data( 'hcsaid' ) != 'undefined' && typeof wc_hcsa_settings.fields[_t.data( 'hcsaid' )] != 'undefined' ) {
  52.                     if ( _t.is( ':checkbox,:radio' ) ) {
  53.                         _t.prop('checked', wc_hcsa_settings.fields[_t.data( 'hcsaid' )]);
  54.                     } else {
  55.                         _t.val(wc_hcsa_settings.fields[_t.data( 'hcsaid' )]);
  56.                     }
  57.                 }
  58.             } );
  59.             switch ( e ) {
  60.                 case 'fade':
  61.                     t.fadeIn( function() { t.removeClass( 'shipping-fields-hidden' ); } );
  62.                     break;
  63.                 case 'none':
  64.                     t.show( 0, function() { t.removeClass( 'shipping-fields-hidden' ); } );
  65.                     break;
  66.                 default:
  67.                     t.slideDown( function() { t.removeClass( 'shipping-fields-hidden' ); } );
  68.             }
  69.         }
  70.     }
  71. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement