title: Change items tax rate in WooCommerce checkout based on radio buttons
body: <p>In WooCommerce I use the plugin [WooCommerce checkout addon][1] and I have added to checkout page an additional field made of radio buttons (multiple choice). I would like to change the tax rate when customer selects a specific choice on that radio buttons field.</p>
  <p>Based on <em><a href="https://stackoverflow.com/questions/55565484/change-woocommerce-cart-items-tax-class-based-on-chosen-payment-method/55569633#55569633">Change Woocommerce cart items tax class based on chosen payment method</a></em> answer code that change tax rate for specific payment method, I have tried to customized the code:</p>
  <pre><code>// Change Tax
  add_action( 'woocommerce_before_calculate_totals', 'change_tax_class_based_on_radio_choice', 10, 1 );
  function change_tax_class_based_on_radio_choice( $cart ) {
      $installation = WC()-&gt;session-&gt;get('wc_checkout_add_ons') ; // This code must be change 
      $value = 'pas-dinstallation' ; // the value of the radio button &quot;woocommerce checkout addon&quot; 
      $value2 = 'bacs' ; // value of payement methode
      $payement_methode = WC()-&gt;session-&gt;get('chosen_payment_method') ;
      //if ( $payement_methode !== $value2 ) //this one is ok for change tax if payement methode is bank transfert
          //return;
      if ( $installation !== $value ) // here i try to set the same condition with one of radio button &quot;woocommerce checkout addon&quot; 
      
  
      return;
      
      if ( is_admin() &amp;&amp; ! defined( 'DOING_AJAX' ) )
          return;
  
      if ( did_action( 'woocommerce_before_calculate_totals' ) &gt;= 2 )
          return;
  
      // Loop through cart items
      foreach( $cart-&gt;get_cart() as $cart_item ){
          // We set &quot;Zero rate&quot; tax class
          $cart_item['data']-&gt;set_tax_class(&quot;Reduced rate&quot;);
      }
  }
  
  add_action('wp_footer', 'option_trigger_update_checkout');
  function option_trigger_update_checkout() {
      if( is_checkout() &amp;&amp; ! is_wc_endpoint_url() ) :
      ?&gt;
      &lt;script type=&quot;text/javascript&quot;&gt;
          jQuery(function($){
              $( 'form.checkout' ).on('change', 'input[type=&quot;radio&quot;]', function() {
                  $(document.body).trigger('update_checkout');
              });
          });
      &lt;/script&gt;
      &lt;?php
      endif;
  }
  </code></pre>
  <p>But I don't know how to make it work for my case yet. I understand that:</p>
  <pre><code>$installation = WC()-&gt;session-&gt;get('wc_checkout_add_ons')
  </code></pre>
  <p>is not well implemented. What I am missing?</p>
  <hr />
  <h3>Update - addition <em>(related to the answer below)</em>:</h3>
  <p>As I don't need to payment method restrictions, I have removed this related line:</p>
  <pre><code>// Only for a specific defined payment method
  if ( ! in_array( WC()-&gt;session-&gt;get('chosen_payment_method'), $payment_ids ) )
      return;
  </code></pre>
  <p><strong>Then code works well indeed now as I expected.</strong></p>
  <p>However, with the &quot;WooCommerce checkout addon&quot; plugin, when a radio button is selected, I can see in administration in the summary of the order and in the email received, what choice has been made.</p>
  <p>with this code, the tax is changed, but I have no information on the customer's radio choice in admin or by email.</p>
  <p>Have you solution?</p>
  <hr />
  <p><strong>Something else:</strong></p>
  <p>I want to move the radio buttons before payment.</p>
  <p>But when I replace this:</p>
  <pre><code>// Display radio buttons field (optional)
  add_action( 'woocommerce_after_order_notes', 'installation_custom_radio_field' );
  function installation_custom_radio_field( $checkout ) {
  </code></pre>
  <p>by</p>
  <pre><code>// Display radio buttons field (optional)
  add_action( 'woocommerce_review_order_before_payment', 'installation_custom_radio_field' );
  function installation_custom_radio_field( $checkout ) {
  </code></pre>
  <p><strong>It doesn't work anymore.</strong> Can you explain why? How to make it work?</p>