title: Shipping carrier custom fields validation in Woocommerce checkout page
body: <p>I have added two custom input fields in the shipping method section by changing the template <code>/genesis-sample/woocommerce/checkout/review-order.php</code>
  I have also managed to get them conditionally required. Only when the specific radio button is checked, the input fields appear and become required. I am using jQuery code to make the fields appear and disappear. All of this is working fine. The code is here:</p>
  
  <pre><code>if ( isset($_POST['shipping_method_0_legacy_local_pickup']) &amp;&amp; $_POST['shipping_method_0_legacy_local_pickup'] == 1 ) {
      $cheq = 'true';
  }
  else {
      $cheq = 'false';
  }
  woocommerce_form_field( 'fieldtester1' , array(
      'type'          =&gt; 'text',
      'class'         =&gt; array('wccs-field-class wccs-form-row-wide blahblah1'), 
      'label'         =&gt; 'Enter Your Carrier Name',
      'required'  =&gt; $cheq,
      'placeholder'       =&gt; 'Carrier Name',
      ), $checkout-&gt;get_value( 'fieldtester1' )); 
  woocommerce_form_field( 'fieldtester2' , array(
      'type'          =&gt; 'text',
      'class'         =&gt; array('wccs-field-class wccs-form-row-wide blahblah2'), 
      'label'         =&gt; 'Enter Your Carrier Account #',
      'required'  =&gt; $cheq,
      'placeholder'       =&gt; 'Carrier Number',
      ), $checkout-&gt;get_value( 'fieldtester2' )); 
  </code></pre>
  
  <p>But here's the problem, even with the <code>required</code> attribute set as <code>true</code> for the two fields, the validation doesn't happen if the field is empty when the <code>Place Order</code> button is pressed. Ideally, the order should not go through and an error message should be generated. I have already added following code in <code>functions.php</code> to force validation of the input field but it doesn't do a thing. The code is here:</p>
  
  <pre><code>add_action('woocommerce_checkout_process', 'carrier_checkout_process');
  function carrier_checkout_process() {
      if ( isset($_POST['shipping_method_0_legacy_local_pickup']) &amp;&amp; $_POST['shipping_method_0_legacy_local_pickup'] == 1 ) {
          if( empty( $_POST['fieldtester1'] ) ) {
              wc_add_notice( ( "Please don't forget to enter your shipping carrier details." ), "error" );
          }
      }
  }
  </code></pre>
  
  <p>So, here's what I am looking for:</p>
  
  <ol>
  <li>can anyone help me in forcing the validation for two input fields I
  have added?</li>
  <li>After the validation, I would also like to add these two fields in the new order email, and order details in the Wordpress dashboard. </li>
  </ol>
  
  <p>If you are wondering why I am not using a woocommerce checkout field hook to add the input fields in the first place...I am not adding the fields to the checkout form so the hooks aren't of any help. The fields are added in the shipping method section. Another reason was, I wanted to update the <code>required</code> attribute every time a user would switch the shipping method. Using Jquery to change the <code>required</code> attribute wasn't working for whatever reason, believe me I tried for two days. Anyways, that part is already working. The only issues are getting the fields to validate and add them to the order emails and order details. I have looked around everywhere and the closest help I got was this post <a href="https://stackoverflow.com/questions/46299376/woocommerce-conditional-custom-checkout-fields">where LoicTheAztec gave a detailed solution</a></p>