I would like to know on how to add text at woocommerce order-received page after the billing address at the bottom?
Is there any hook I can used?
Or any other way can accomplished this?
In the WooCommerce > Settings > Payments > Thank you pages section there is a setting to enable “Thank you page navigation”.
The default WooCommerce thank you pageThe order number, date, customer email, total, payment method, products purchased, and billing information are included by default. Let's explore some ways we can add some basic customizations to improve the thank you page.
Try this custom hooked function in woocommerce_thankyou
action hook:
add_action( 'woocommerce_thankyou', 'custom_content_thankyou', 10, 1 );
function custom_content_thankyou( $order_id ) {
echo '<p>'. __('My custom text').'</p>';
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works…
You can add action hooks inside your (child) theme or a plugin. Expanding @LoicTheAztec's answer:
add_action( 'woocommerce_thankyou', 'custom_content_thankyou', 10, 1 );
function custom_content_thankyou( $order_id ) {
echo '<p>'. __('My custom text').'</p>';
}
Here are more actions that you can use, that are unfortunately not (yet?) mentioned in the official WooCommerce Action and Filter Hook Reference documentation:
woocommerce_before_thankyou
woocommerce_thankyou_{payment_method}
(dynamic)woocommerce_thankyou
There are times when you need the order details and shipping method. To get the order details you can use $order = new WC_Order($order_id);
. For example:
function produkindo_before_thankyou($order_id) {
$order = new WC_Order($order_id);
// Iterating through order shipping items
foreach( $order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ){
// $order_item_name = $shipping_item_obj->get_name();
// $order_item_type = $shipping_item_obj->get_type();
// "Prahu-Hub" or "Prahu - Hub"
$shipping_method_title = $shipping_item_obj->get_method_title();
$shipping_method_id = $shipping_item_obj->get_method_id(); // The method ID
$shipping_method_instance_id = $shipping_item_obj->get_instance_id(); // The instance ID
// $shipping_method_total = $shipping_item_obj->get_total();
// $shipping_method_total_tax = $shipping_item_obj->get_total_tax();
// $shipping_method_taxes = $shipping_item_obj->get_taxes();
break;
}
if (preg_match('/^Prahu/i', $shipping_method_title)) {
?>
<div class="prahu-hub-thankyou">
Silakan melanjutkan pemesanan pengiriman untuk barang yang Anda beli di <a target="_blank" href="https://prahu-hub.com/home/pencarian"><strong>Prahu–Hub</strong></a>.
</div>
<?php
}
}
add_action('woocommerce_before_thankyou', 'produkindo_before_thankyou');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With