WooCommerce - 在 Thankyou order received 页面上自定义 "Total" 文本

WooCommerce - Customize "Total" text on Thankyou order received page

在 WooCommerce 中,我的感谢页面出现问题(一旦客户下订单)。我试图手动更改它,但问题是代码是在一个我找不到的未知文件中生成的。

    <tfoot>
        <?php
                foreach ( $order->get_order_item_totals() as $key => $total ) {
                    ?>
                    <tr>
                        <th scope="row"><?php echo $total['label']; ?></th>
                        <td><?php echo $total['value']; ?></td>
                    </tr>
                    <?php
                }
            ?>
    </tfoot>

此代码为我提供订单中的所有信息,如优惠券、运费等。

在这张图片上,我想替换黑色边框矩形中的文本(这里 'Gesamt:' 意思是 "Total" 来自 "Total inkl. vat"

我还想删除红色边框的矩形块:"Inkl. 19% MwSt."

可能吗?
我该怎么做?

谢谢。

嘿,我想这对你有用

只要确保 inkl. 19%.... 写对了。

foreach ( $order->get_order_item_totals() as $key => $total ) {
    ?>
    <tr>
        <th scope="row"><?php echo ($total['label']=='inkl. 19% Mwst.'?'Vat Only':$total['label']); ?></th>
        <td><?php echo $total['value']; ?></td>
    </tr>
    <?php
}

此处是在感谢页面中加载的 woocommerce/order/order-details.php 模板结尾的摘录。

To override the 'Total' text displayed by foreach loop with the method get_order_item_totals() applied to the $order object (that generate an array of key/values), you have to add a condition for each language used by your web site. Here in my code you got english and german.

在您的活动主题中转到 woocommerce > order,然后 open/edit order-details.php 模板文件。

将模板末尾替换为:

    <tfoot>
        <?php
            $order_item_totals = $order->get_order_item_totals();
            $count_lines = count($order_item_totals) - 1;
            $count = 0;
            foreach ( $order_item_totals as $key => $total ) {
                $count++;
                // The condition to replace "Total:" text in english and german
                if( $total['label'] == 'Total:' || $total['label'] == 'Gesamt:')
                    $total_label = __( 'Total inkl. vat:', 'woocommerce' );
                else 
                    $total_label = $total['label'];
                // End of the condition
                ?>
                <tr>
                    <th scope="row"><?php echo $total_label; // <== == Replaced $total['label'] by $total_label ?></th>
                    <td><?php echo $total['value']; ?></td>
                </tr>
                <?php
                // this should avoid displaying last line
                if( $count >= $count_lines ) break;
            }
        ?>
    </tfoot>
</table>

<?php do_action( 'woocommerce_order_details_after_order_table', $order ); ?>

<?php if ( $show_customer_details ) : ?>
    <?php wc_get_template( 'order/order-details-customer.php', array( 'order' =>  $order ) ); ?>
<?php endif; ?>

现在可以保存了,大功告成……

此代码已经过测试并且有效。

参考文献: