title: woocommerce custom checkout field to add fee to order ajax
body: <p>I'm trying to ad a custom fee to the order total upon checkout.
  I've added a checkbox within woocommerce</p>
  
  <pre><code>add_action( 'woocommerce_after_checkout_billing_form', 'add_box_option_to_checkout' );
  function add_box_option_to_checkout( $checkout ) {
      echo '&lt;div id="message_fields"&gt;';
      woocommerce_form_field( 'add_gift_box', array(
          'type'          =&gt; 'checkbox',
          'class'         =&gt; array('add_gift_box form-row-wide'),
  
          'label'         =&gt; __('Ilość pudełek ozdobnych - 25 PLN/szt'),
          'placeholder'   =&gt; __(''),
          ), $checkout-&gt;get_value( 'add_gift_box' ));
  }
  </code></pre>
  
  <p>Included a custom js file which schould handle the event</p>
  
  <pre><code>jQuery( document ).ready(function( $ ) {
  
    $('#add_gift_box').click(function(){
          var data = {
              action: 'woocommerce_add_gift_box',
              state: '200',
          };
          jQuery.ajax({
              type: 'POST',
              url: wc_checkout_params.ajax_url,
              data: data,
              success: function (code) {
                  console.log(code);
                  jQuery('body').trigger('update_checkout');
              },
              dataType: 'html'
          });
  
    });
  });
  </code></pre>
  
  <p>And a php fee handling function</p>
  
  <pre><code>function woo_add_cart_fee( $data ){
    if ( is_admin() &amp;&amp; ! defined( 'DOING_AJAX' ) || ! $_POST )  return;
  
    $extracost = 0;
    if (isset($_POST['state'])) {
      $extracost = intval($_POST['state']);
    }
    WC()-&gt;cart-&gt;add_fee( 'Ozdobne pudełka:', $extracost );
  
  }
  add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
  
  
  add_action('wp_ajax_woocommerce_add_gift_box', 'woo_add_cart_fee', 10);
  add_action('wp_ajax_nopriv_woocommerce_add_gift_box', 'woo_add_cart_fee', 10);
  </code></pre>
  
  <p>For some reasons the value of $_POST['state'] isn't added, the function works when I give a hard coded value, I've tried many option but cant get this to work.</p>
  
  <p>I've seen similar posts but none of them had the answer.</p>