【问题标题】:Customize Woocommerce PIP add row to invoice自定义 Woocommerce PIP 将行添加到发票
【发布时间】:2018-03-23 03:29:38
【问题描述】:

我有一个不显示增值税的 Woocommerce 网站,客户不希望改变这一点。

我已经购买了 WooCommerce 打印发票/装箱单。

我想在表格底部添加一个额外的行,使用基于发票总额的简单计算来计算发票中的增值税。

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

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

谁能指出我正确的方向?

谢谢

【问题讨论】:

    标签: php wordpress printing woocommerce invoice


    【解决方案1】:

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

    【讨论】:

    • 我可以将订单子总金额更改为 [price]/1.2 吗?
    • 我添加了一些额外的代码来展示如何在不重新排序的代码中从 $order_id 获取总数。
    • 在我修改后的答案中添加了上面的内容。
    • 对不起,但价格仍然保持“价值” => wc_price(10) ?
    • DOH - 我找到了 - 抱歉!
    猜你喜欢
    • 2015-06-07
    • 1970-01-01
    • 2021-11-28
    • 2021-07-07
    • 2022-01-25
    • 2017-07-14
    • 2022-07-01
    • 2011-03-08
    • 1970-01-01
    相关资源
    最近更新 更多