Customize the text “Total” in WooCommerce checkout page

社会主义新天地 提交于 2019-11-27 07:57:31

问题


I would like to change the the "Total" text in my checkout page to "Total inkl. vat". I have tried different things without success…

Here is what I am targeting:

<?php _e( 'Total', 'woocommerce' ); ?>

This is the code snippet. I've searched in all language files but i can't find anything. I've installed the Q translate plugin but I don't think it's the problem.

I could code it hard, but thats not a good solution because I've to do this edit in all my files.

How can I achieve this please?

Thanks


回答1:


OPTION 1 (best option)

Overriding the woocommerce checkout/review-order.php template.

You need first (if not done) to copy the templates sub folder located in in woocommerce plugin folder to your active child theme (or theme) folde, and rename it woocommerce.

Once done in your active theme go to woocommerce > checkout, and open/edit review-order.php template file.

At the end of this template you have this:

        <?php do_action( 'woocommerce_review_order_before_order_total' ); ?>

        <tr class="order-total">
            <th><?php _e( 'Total', 'woocommerce' ); ?></th>
            <td><?php wc_cart_totals_order_total_html(); ?></td>
        </tr>

        <?php do_action( 'woocommerce_review_order_after_order_total' ); ?>

    </tfoot>
</table>

So you will change:

<th><?php _e( 'Total', 'woocommerce' ); ?></th>

To:

<th><?php _e( 'Total inkl. vat', 'woocommerce' ); ?></th>

Now you can save, you are done…

References:

  • Template Structure + Overriding Templates via a Theme
  • Woocommerce template checkout > review-order.php

OPTION 2 (Not ideal, see below)

You could use wordpress gettex() native function for that purpose, this way:

add_filter('gettext', 'wc_renaming_checkout_total', 20, 3);
function wc_renaming_checkout_total( $translated_text, $untranslated_text, $domain ) {

    if( !is_admin() && is_checkout ) {
        if( $untranslated_text == 'Total' )
            $translated_text = __( 'Total inkl. vat','theme_slug_domain' );
    }
    return $translated_text;
}

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

But you will get 2 customized texts in the prices table, because there is 2 "Total" texts (once in the first line after 'Products') and one time at the end…

This code is tested and works.



来源:https://stackoverflow.com/questions/39458027/customize-the-text-total-in-woocommerce-checkout-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!