WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Changing tax with a radio button

[Resolved] Changing tax with a radio button

  • Kieran McClung

    @kieranmcclung

    Hello,
    I’m currently trying to add something to my checkout which allows people to select whether they’re using the products domestically or commercially. Once this radio button is checked it should change the tax rate (domestic 5%, commercial 20%). 20% is the default at the moment.

    So:

    function kierans_vat_check($vatType) {
       ?>
    
       <form method="post" id="vatChange" action="accept">
          <label>
             <input name="vatCheck" type="radio" value="commercial" onclick="this.form.submit();" /> Commercial VAT
          </label>
          <br>
          <label>
             <input name="vatCheck" type="radio" value="domestic" onclick="this.form.submit();" /> Domestic VAT
          </label>
       </form>  
    
       <?php
    
       $vatType = $_POST['vatCheck'];
       return $vatType;
    }
    
    // Woocommerce select domestic (reduced rate) tax (commercial is default)
    add_filter('woocommerce_product_tax_class', 'big_apple_get_tax_class', 1, 2);
    
    function big_apple_get_tax_class($tax_class, $product, $vatType) {
       global $woocommerce;
       global $vatType;
    
       if($vatType == 'Domestic'):
          $tax_class = 'Reduced Rate';
       endif;
    
       return $tax_class;
    }

    What I’m trying to do here is run the big_apple_get_tax_class function when the radio button value is domestic. The form seems to be working fine however I can’t seem to get the variable into the big_apple function. I’ve also tried including the big_apple function within the kierans_vat_check and just doing the if from there but that wasn’t working either.

    Any help would be greatly appreciated.

    Thank you.

    http://wordpress.org/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • Kieran McClung

    @kieranmcclung

    It appears I over-complicated this. Variable product has worked just fine for this.

Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Changing tax with a radio button’ is closed to new replies.