Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WooCommerce tax on seperate line WordPress

  • SOLVED

Hi,

I'm trying to modify get_order_item_totals() ([[LINK href="https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-order.php"]]class-wc-order.php[[/LINK]]) in order to display tax on a seperate line on the order received page and in the order confirmation emails. I'm using the woocommerce_get_order_item_totals filter:

add_filter('woocommerce_get_order_item_totals','dks_tax_new_line');
function dks_tax_new_line($total_rows) {
//Define order total again without the (Includes %s) label
$total_rows['order_total']['value'] = $this->get_formatted_order_total();

//Make an array with tax
$taxes = array();
foreach ( $this->get_tax_totals() as $code => $tax ) {
$taxes[] = sprintf( '%s', $tax->formatted_amount );
}

//Add the tax row to the array that get_order_item_totals() outputs
$total_rows['tax_line'] = array(
'label' => 'Herfra 25% Moms:',
'value' => sprintf( implode( ', ', $taxes ) )
);

return $total_rows;
}


Obviously I cannot use $this but then how do I get the order total and tax amount? You should know that I'm no programmer and I can only write a few basic codes.

I hope somebody can help.
Thank you!

Answers (2)

2014-01-26

Dbranes answers:

You can try this

add_filter( 'woocommerce_get_order_item_totals', 'dks_tax_new_line', 10, 2 );

function dks_tax_new_line( $total_rows, $myorder_obj )
{
// your code, but replace $this with $myorder_obj
}


Emil Eriksen comments:

Thank you! It works perfectly :D So simple...

2014-01-25

Arnav Joy answers:

why you don't use following function to get the tax

get_total_tax()

like

$WC_Order = new WC_Order();

echo $WC_Order->get_total_tax();


Emil Eriksen comments:

Thanks for the reply but that just returns 0.00. I need to get the tax for an order after it has been placed so I can't just do new WC_Order(). That would be like making an empty order, I think.