【问题标题】:WooCommerce - Customize "Total" text on Thankyou order received pageWooCommerce - 在收到的谢谢订单页面上自定义“总计”文本
【发布时间】:2017-01-21 15:04:52
【问题描述】:

在 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."

有可能吗?
我该怎么做?

谢谢。

【问题讨论】:

    标签: php wordpress woocommerce gettext orders


    【解决方案1】:

    这里是在感谢页面中加载的 woocommerce/order/order-details.php 模板末尾的摘录。

    使用 get_order_item_totals() 方法覆盖 foreach 循环显示的 'Total' 文本到 @ 987654329@ 对象(生成 key/values 的数组),您必须为您的网站使用的每种语言添加一个条件。在我的代码中,你有英语和德语。

    在您的活动主题中转到 woocommerce &gt; order,然后打开/编辑 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; ?>
    

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

    此代码已经过测试并且可以工作。

    参考资料:

    【讨论】:

    • 谢谢!你知道现在从这个网站上删除额外描述的大桶的方法吗?谢谢
    • 我可以给你写一封电子邮件,但我会在这里回复,因为如果其他人需要这个答案,你知道吗?我的意思是我图片中的红色矩形区域。首先,我添加了包含。增值税到总标签,现在我想从这个循环中删除红色字段,因为我不想显示额外的增值税
    • @Johnny97 我现在才真正完全理解您的问题。因此,我更新了您的问题以使其更清晰,并更新了我的答案(您必须测试它,因为我没有)。如果可行,请在此处评论我。
    • 天哪,我很高兴 :) 非常感谢!它对我来说很好。
    • 我有一种不好的感觉要再问你一次……但是你知道答案吗? stackoverflow.com/q/39549281/6580560 我尝试为帐户页面制作一个 wordpress 自定义模板并插入 到此为止,但之后我的页面出现错误...
    【解决方案2】:

    嘿,我认为这对你有用

    只要确保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
    }
    

    【讨论】:

    • 也感谢您的帮助!
    猜你喜欢
    • 2021-06-12
    • 1970-01-01
    • 2021-10-16
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    相关资源
    最近更新 更多