Reputation: 73
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?
Upvotes: 6
Views: 12941
Reputation: 21384
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');
Upvotes: 4
Reputation: 253784
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…
Upvotes: 12