Customizing WooCommerce review-order.php checkout template

Justin picture Justin · Dec 2, 2016 · Viewed 8.2k times · Source

So I am working on WooCommerce with a Child-theme. I have created my structure,

/themes/child/woocommerce/checkout/review-order.php

My goal is just to add some 'static text' to the page. So for example, <h2>Purchase Disclaimer</h2>

Inside review-order.php

<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
?>
<h2>Purchase Disclaimer</h2>

My problem is, when I view the page, it then goes,

<h2>Purchase Disclaimer</h2>
<h2>Purchase Disclaimer</h2>

I don't know why it seems to load it 2 times. Is this a glitch, or am I loading it weird? Perhaps someone could help clarify this issue for me.

Thanks in advance

Answer

LoicTheAztec picture LoicTheAztec · Dec 2, 2016

Checkout review-order table load first one time and then ajax is making a 2nd loading (for update purposes is suppose), so you have to use a little condition to avoid that:

<?php if(!defined( 'DOING_AJAX' )): ?>
<h2>Purchase Disclaimer</h2>
<?php endif; ?>

You should avoid <h2> tag as it's already use for <h3 id="order_review_heading">Your order</h3>

Alternatively you can use instead a hooked function in woocommerce_checkout_before_order_review hook this way:

add_action('woocommerce_checkout_before_order_review', 'my_custom_funtion');
function my_custom_funtion(){
    ?>
        <h2>Purchase Disclaimer2</h2>
    <?php
}

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