title: Change Tax according to vendor product on shipping
body: <p>I am trying to add tax functionality according to vendor product and vendors have allowed different shipping address.</p>
  
  <p>I have added the functionality for vendor to select specific tax location and on checkout using this code get tax but unable to update tax after order completed. I am using Dokan multi vendor plugin.</p>
  
  <p>Simply want to add tax on allowed shipping address by vendor.</p>
  
  <pre><code>function filter_woocommerce_calc_tax( $taxes, $price, $rates, $price_includes_tax, $suppress_rounding) {    
       global $woocommerce;
       global $wpdb;  
       $subTotal=$woocommerce-&gt;cart-&gt;subtotal;
       $table = $wpdb-&gt;prefix.'tax_state_by_vendor'; 
       $cart = WC()-&gt;cart-&gt;get_cart(); 
       $reqTaxStat=0;
       $reqTaxStat = $wpdb-&gt;get_row("select tax_rate_id from wpyp_woocommerce_tax_rates WHERE tax_rate_country = '".$_REQUEST['s_country']."' and tax_rate_state = '". $_REQUEST['s_state']."'"); 
       $Qunatity=1;
  
       $productDetails = array();
          $i = 0;
          foreach( $cart as $key =&gt; $cart_item ){
              $Qunatity += $cart_item['quantity'];
              $post_obj    = get_post( $cart_item['product_id'] ); // The WP_Post object
              $productDetails[$i]['product_id'] = $cart_item['product_id'];       
              $productDetails[$i]['vendor_id'] = $post_obj-&gt;post_author;  
              $taxes = $wpdb-&gt;get_row("select tax_id from $table WHERE vendor_id = ".$post_obj-&gt;post_author); 
              $productDetails[$i]['vendor_tax_states'] = $taxes-&gt;tax_id;
              $taxDetails = $wpdb-&gt;get_results("select wrt.tax_rate,wrt.tax_rate_country,wrt.tax_rate_state from wpyp_tax_state_by_vendor tv left join wpyp_woocommerce_tax_rates wrt on find_in_set(wrt.tax_rate_id, tv.tax_id) &gt; 0
              WHERE tv.vendor_id = ".$post_obj-&gt;post_author);
  
              $productDetails[$i]['vendor_tax_details'] = array();
              foreach($taxDetails as $tkeys =&gt; $tval){
                  $productDetails[$i]['vendor_tax_details'][$tkeys]['tax_price'] = $tval-&gt;tax_rate;
                  $productDetails[$i]['vendor_tax_details'][$tkeys]['tax_country'] = $tval-&gt;tax_rate_country;
                  $productDetails[$i]['vendor_tax_details'][$tkeys]['tax_state'] = $tval-&gt;tax_rate_state;
              }
              $productDetails[$i]['product_total_rpice'] = get_post_meta($cart_item['product_id'] , '_price', true);
              $i++;
          }
       $totalTax = 0;
  
       if(!empty($productDetails)){
          foreach($productDetails as $pkey =&gt; $pval){
              foreach($pval['vendor_tax_details'] as $taxD){
                  if(($_REQUEST['s_country'] == $taxD['tax_country']) &amp;&amp; ($_REQUEST['s_state'] == $taxD['tax_state'])){
                       $totalTax += $pval['product_total_rpice'] * $taxD['tax_price'] / 100;
                  }
              }
          }
       }
       if(isset($totalTax)){
      // echo $Qunatity;
       // print_r(array($reqTaxStat-&gt;tax_rate_id =&gt; $totalTax));die;
          return array($reqTaxStat-&gt;tax_rate_id =&gt; $totalTax * 100 / count($cart));
       } 
  
      return taxes;
  }
  
  add_filter( 'woocommerce_calc_tax', 'filter_woocommerce_calc_tax', 10, 5);
  </code></pre>
  
  <p>Can anybody help me how will I add tax according to vendor allowed product.</p>