donglian8407 2016-09-13 22:11
浏览 116
已采纳

WooCommerce - 在Thankyou订单收到页面上自定义“总计”文本

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.

enter image description here

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

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

Is it possible?
How can I do it?

Thanks.

  • 写回答

2条回答 默认 最新

  • duanou3868 2016-09-13 23:30
    关注

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

    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.

    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…

    This code is tested and works.

    References:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上