Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a text in Woocommerce order received page after the billing address

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?

like image 760
user8875458 Avatar asked Nov 02 '17 15:11

user8875458


People also ask

How do I customize my WooCommerce thank you page?

In the WooCommerce > Settings > Payments > Thank you pages section there is a setting to enable “Thank you page navigation”.

What is the default WooCommerce thank you page?

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.


2 Answers

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…

like image 171
LoicTheAztec Avatar answered Nov 01 '22 21:11

LoicTheAztec


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:

  1. woocommerce_before_thankyou
  2. woocommerce_thankyou_{payment_method} (dynamic)
  3. 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');
like image 35
Hendy Irawan Avatar answered Nov 01 '22 22:11

Hendy Irawan