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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!