I am trying to make select box to change tax class at admin order detail in Woo. I made column, select box with tax classes, when the product is one, it works perfectly. But when i have more than 2 products it gets tax class what have the last of the list (you can see it in video). I would like to be able to set tax class for every item separately... Thanks for help
Here is video
My code in functions.php is like that
function tax_edit_col_h($order){
?>
<th class="line_changetax">
Změna daně
</th>
<?php
}
add_action( 'woocommerce_admin_order_item_headers', 'tax_edit_col_h' );
function tax_change($item_id, $item, $product) {
if('line_item' === $item->get_type()){
?>
<td class="line_changetax" style="width:20%">
<select name="change_tax" id="change_tax_select" style="width:90%; display:inline-block">
<?php
$arraytax = WC_Tax::get_tax_class_slugs();
echo '<option value="'.$item->get_tax_class().'">'.$item->get_tax_class().'</option>';
foreach($arraytax as $tax){
echo '<option value="'.$tax.'">'.$tax.'</option>';
}
?>
</select>
</td>
<?php
}
}
add_action( 'woocommerce_admin_order_item_values', 'tax_change', 10, 3 );
function change_order_item_tax_class( $item ) {
if (isset($_POST['change_tax']) ) {
$item->set_tax_class($_POST['change_tax']);
}
}
add_action( 'woocommerce_before_save_order_item', 'change_order_item_tax_class' );