This topic has 4 replies, 2 voices, and was last updated 3 months ago ago by Luca Rossi
hi, i need to add a custom text before the discount/fee section and after the shipping section. as per the screen shot
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!
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
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!
You must be logged in to reply to this topic.Log in/Sign up