自定义Woocommerce PIP添加行以开票
问题描述:
我有Woocommerce网站不显示增值税,客户不希望更改。自定义Woocommerce PIP添加行以开票
我已经购买了WooCommerce打印发票/装箱清单。
我想在表格底部添加一行,并使用基于发票总额的简单计算来计算发票中的增值税额。
我已经通过编辑order-table.php来实现这一目标,但希望通过在functions.php中添加一个过滤器来实现。我看过https://docs.woocommerce.com/document/woocommerce-print-invoice-packing-list/,但似乎无法达到我所需要的。
任何人都可以指向正确的方向吗?
谢谢
答
我在通过代码搜索后发现了一个过滤器。我甚至增加了一些额外的代码来重新排列这些值,以便增值税出现在总额之前。如果你不想这样做,我会发布解决方案,而无需重新排序。我已经添加了10美元的虚拟价格,您可以用您的计算来替换。
function modify_wc_pip_document_table_footer($rows, $type, $order_id) {
$tmp_rows = array();
$tmp_rows['cart_subtotal'] = $rows['cart_subtotal'];
$tmp_rows['payment_method'] = $rows['payment_method'];
$tmp_rows['vat'] = array('vat_total' => '<strong class="order-order_total">VAT Total:</strong>',
'value' => wc_price(10)
);
$tmp_rows['order_total'] = $rows['order_total'];
return $tmp_rows;
}
add_filter('wc_pip_document_table_footer', 'modify_wc_pip_document_table_footer', 10, 3);
没有重新排序
function modify_wc_pip_document_table_footer($rows, $type, $order_id) {
$order = wc_get_order($order_id);
$order_total = $order->get_total();
$rows['vat'] = array('vat_total' => '<strong class="order-order_total">VAT Total:</strong>',
'value' => wc_price(600)
);
return $rows;
}
add_filter('wc_pip_document_table_footer', 'modify_wc_pip_document_table_footer', 10, 3);
这是完美的.....我如何获取订单总额? – Deb
CAn我将订单子总金额更改为[price] /1.2? – Deb
我添加了一些额外的代码,以显示如何从无序重新排序代码中的$ order_id中获得总数。 –