WooCommerce-自定义“总计"谢谢订单收到页面上的文字 [英] WooCommerce - Customize "Total" text on Thankyou order received page

查看:106
本文介绍了WooCommerce-自定义“总计"谢谢订单收到页面上的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In WooCommerce I have a problem on my thankyou page (once the customer has placed his order). I have tryed to change it manualy but the problem is that the code is generated in an unknown file which I can't find.

    <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>

此代码为我提供了订单中的所有信息,例如优惠券,运输等.

This code give me all information in my order like a coupon the shipping etc.

在这张照片上,我想用黑色边框代替文本(此处 'Gesamt:' 表示 "Total" "Total inkl. vat"

On this picture I would like to replace the text in the black bordered rectangle (Here 'Gesamt:' mean "Total" by "Total inkl. vat"

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

Also I want to remove the red bordered rectangle block: "Inkl. 19% MwSt.".

有可能吗?
我该怎么办?

Is it possible?
How can I do it?

谢谢.

推荐答案

以下是 woocommerce/order/order-details.php 模板上末尾的摘要,该模板已加载到谢谢"页面中.

Here the extract of the end on woocommerce/order/order-details.php template that is loaded in thank you page.

要使用 get_order_item_totals() 方法将 foreach 循环显示的 'Total' 文本覆盖到 $order 对象(生成 key/values 的数组),您必须为网站使用的每种语言添加条件.在我的代码中,您得到了英语和德语.

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 ,然后打开/编辑 order-details.php 模板文件.

In your active theme go to woocommerce > order, and open/edit order-details.php template file.

使用以下内容替换模板的结尾:

Replace the end of your template with this:

    <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; ?>

现在您可以保存,您就完成了……

Now you can save, you are done…

此代码已经过测试并且可以正常工作.

参考:

  • Template Structure + Overriding Templates via a Theme
  • Woocommerce template checkout > review-order.php
  • Customize the text "Total" in WooCommerce checkout page

这篇关于WooCommerce-自定义“总计"谢谢订单收到页面上的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆