自定义 Woocommerce PIP 添加行到发票

Customize Woocommerce PIP add row to invoice

我的 Woocommerce 网站不显示增值税,客户不希望这种情况发生变化。

我已经购买了 WooCommerce Print Invoices/Packing 列表。

我想在 table 的底部添加一行,使用基于发票总额的简单计算来计算发票中有多少增值税。

我已经通过编辑 order-table.php 实现了这一点,但更愿意通过向 functions.php 添加过滤器来添加它。

我看过 https://docs.woocommerce.com/document/woocommerce-print-invoice-packing-list/ 但似乎无法实现我需要的。

谁能指出我正确的方向?

谢谢

我在搜索代码后发现了一个过滤器。我什至添加了一些额外的代码来重新排序值,以便增值税出现在总数之前。如果您不希望那样,我将 post 解决方案也无需重新排序。我添加了 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 );