I want to display a set of order details on the thank you page of my WooCommerce checkout. There are some already and I found them in the template thankyou.php
.
But I need them in an extra div
to add a tool called "Trusted Shops".
So I tried the following code:
add_action( 'woocommerce_order_details_before_order_table', 'trusted_shops_thankyou', 15, 1 );
function trusted_shops_thankyou( $order_id ) {
echo 'tsCheckoutOrderNr: '.$order->get_order_number();
echo 'tsCheckoutBuyerEmail: '.$order->get_billing_email();
echo 'tsCheckoutOrderAmount: '.$order->get_formatted_order_total();
echo 'tsCheckoutOrderCurrency: '.$order->get_order_number();
echo 'tsCheckoutOrderPaymentType: '.wp_kses_post( $order->get_payment_method_title());
echo 'tsCheckoutOrderEstDeliveryDate: '.$order->get_order_number();
// I need to fill the following DIVs
echo '
<div id="trustedShopsCheckout" style="display: none;">
<span id="tsCheckoutOrderNr">2016-05-21-001</span>
<span id="tsCheckoutBuyerEmail">[email protected]</span>
<span id="tsCheckoutOrderAmount">4005.95</span>
<span id="tsCheckoutOrderCurrency">EUR</span>
<span id="tsCheckoutOrderPaymentType">VORKASSE</span>
<span id="tsCheckoutOrderEstDeliveryDate">2016-05-24</span>
</div>
<div id="customCheckoutDiv"></div>
';
}
The problem is, that I don't get the data from $order
.
I get the following error:
Fatal error: Uncaught Error: Call to a member function get_order_number() on null in....
I tried to add this code but it doesn't help:
global $woocommerce, $post;
$order = new WC_Order($post->ID);
What is missing? How could I get the data from $order
?
And bonus: How could I get the estimated delivery date? ;)
I got it!
I need to change that:
function trusted_shops_thankyou( $order_id )
to that:
function trusted_shops_thankyou( $order )