Add custom text on order review section on the checkout page

This topic has 4 replies, 2 voices, and was last updated 3 months ago ago by Luca Rossi

  • Avatar: Anas
    Anas
    Participant
    September 16, 2024 at 12:15

    hi, i need to add a custom text before the discount/fee section and after the shipping section. as per the screen shot

    Please, contact administrator
    for this information.
    Files is visible for topic creator and
    support staff only.
    3 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    September 17, 2024 at 04:29

    Hi @Anas,

    Please add the following code under functions.php file locates in your child theme:

    
    add_action('woocommerce_review_order_before_order_total', 'n2t_woocommerce_review_order_before_order_total', 1);
    function n2t_woocommerce_review_order_before_order_total(){
    echo 'Your custom text';
    }
    

    You can replace the woocommerce_review_order_before_order_total hook with the other hooks there: https://www.businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/.

    Hope it helps!

    Avatar: Anas
    Anas
    Participant
    September 17, 2024 at 05:09

    thanks, but i have already tried this hook, it shows on top of the page. not before order total. screenshot attached. also it shows the hook 2 times

    Files is visible for topic creator and
    support staff only.
    Avatar: Justin
    Luca Rossi
    Support staff
    September 17, 2024 at 09:52

    Hi @Anas,

    We can confirm the hooks didn’t work on our end too.

    In this case, we suggest you to copy this file to your child theme in the same as directory then edit directly the template file:

    – /wp-content/themes/xstore/woocommerce/checkout/review-order.php
    – /wp-content/themes/xstore-child/woocommerce/checkout/review-order.php

    – Take a look at this code around line 179-184

    
            <?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
                <tr class="fee">
                    <th><?php echo esc_html( $fee->name ); ?></th>
                    <td><?php wc_cart_totals_fee_html( $fee ); ?></td>
                </tr>
            <?php endforeach; ?>
    

    – Then add your custom text:

    
            <?php foreach ( WC()->cart->get_fees() as $fee ) : ?>
                <tr class="fee">
                    <th><?php echo esc_html( $fee->name ); ?></th>
                    <td><?php wc_cart_totals_fee_html( $fee ); ?></td>
                </tr>
            <?php endforeach; ?>
    
                <tr class="custom-text">
                    <td colspan="2">You custom text</td>
                </tr>
    

    Hope it helps!

  • Viewing 4 results - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.