title: reload a PHP condition with ajax (Woocommerce)
body: <p>I have added one custom field (select tag) to checkout page that is output of two conditions:</p>
  <p>1st &gt;&gt; If &quot;Victoria&quot; state is selected then display first condition as custom field.</p>
  <p>2nd &gt;&gt; If any other state is selected then display second condition as custom field.</p>
  <pre><code>// Add custom checkout datepicker field to checkout page
  
  add_action( 'woocommerce_before_order_notes', 'checkout_display_datepicker_custom_field' );
  function checkout_display_datepicker_custom_field( $checkout ) {
      
      echo '&lt;div id=&quot;datepicker-wrapper&quot; style=&quot;width:22%;&quot;&gt;';
      
         $field_id = 'my_datepicker';
         $state_code = 'VIC';
         $today = strtotime('today');
         $tomorrow = strtotime('tomorrow');
         $dayAfterTomorrow = strtotime('+2 days');
      
  // First Condition, If &quot;VICTORIA&quot; is selected
  
   if( WC()-&gt;customer-&gt;get_billing_state() === $state_code ){
       
       woocommerce_form_field(  $field_id, array(
          'type'          =&gt; 'select',
          'class'         =&gt; array('form-row-wide'),
          'label' =&gt; __('Delivery Date For Victoria'),
          'placeholder'   =&gt; __('Select Delivery Date For Victoria'),
          'required' =&gt; true, // Or false
          'options'     =&gt; array(
              '' =&gt; 'Select',
              date(('d F Y'), $today ) =&gt; date(('d F Y'), $today ),
              date(('d F Y'), $tomorrow ) =&gt; date(('d F Y'), $tomorrow ),
          )));
  
       echo '&lt;br&gt;&lt;/div&gt;';
       
          } else {
  
   // Second Condition, If other state is selected
          
          woocommerce_form_field(  $field_id, array(
          'type'          =&gt; 'select',
          'class'         =&gt; array('form-row-wide'),
          'label' =&gt; __('Delivery Date'),
          'placeholder'   =&gt; __('Select Delivery Date'),
          'required' =&gt; true, // Or false
          'options'     =&gt; array(
              '' =&gt; 'Select',
              date(('d F Y'), $tomorrow ) =&gt; date(('d F Y'), $tomorrow ),
              date(('d F Y'), $dayAfterTomorrow ) =&gt; date(('d F Y'), $dayAfterTomorrow ),
          )));
  
       echo '&lt;br&gt;&lt;/div&gt;';                 
  
          }  
  }
  </code></pre>
  <p>Then I need a jQuery to reload above conditions on every state change and display custom field based on choosed state, I tried this script but it doesn't work:</p>
  <pre><code>//jQuery to refresh custom field (delivery date) based on choosed state
  
  add_action('wp_ajax_woo_modify_state', 'delivery_date', 10);
  add_action('wp_ajax_nopriv_woo_modify_state', 'delivey_date', 10);
  
  function delivery_date() {
      // On checkout
      if ( is_checkout() &amp;&amp; ! is_wc_endpoint_url() ) :
      ?&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
  
  jQuery(document).ready(function () {
      jQuery('#billing_state').change(function(){
          jQuery.ajax({
              url: wc_checkout_params.ajax_url,
              type: &quot;post&quot;,
              data: {option: jQuery(this).find(&quot;option:selected&quot;).val()},
              success: function(data){
                  //adds the echoed response to our container
                  jQuery(&quot;#my_datepicker&quot;).html(data);
              }
          });
      });
  });
  
      &lt;/script&gt;
      
      &lt;?php
      endif;
  }
  </code></pre>
  <p>Am I using a correct method to reload a PHP condition with ajax? I don't see any error on console and that is why I am confused with it.</p>