Customize the text "Total" in WooCommerce checkout page

Johnny97 picture Johnny97 · Sep 12, 2016 · Viewed 11k times · Source

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

Answer

LoicTheAztec picture LoicTheAztec · Sep 13, 2016

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:


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.