将Woocommerce税显示为单独的表格行

时间:2018-08-16 07:56:01

标签: php wordpress woocommerce

我正在使用Woocommerce,并且希望在总计上方(在购物车和结帐栏中)的单独表格行中显示税款(“含税”),而不是像这样按正则显示在同一行中总计的后面默认。我找到了

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 = [];
    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'] = [
        'label' => 'Herfra 25% Moms:',
        'value' => sprintf(implode(', ', $taxes)),
    ];

    return $total_rows;
}

但是它不起作用。有人可以帮忙吗? 谢谢!

0 个答案:

没有答案