从 WooCommerce 的感谢页面上的 $order 获取数据

Get data from $order on thank you page in WooCommerce

我想在我的 WooCommerce 结帐的感谢页面上显示一组订单详细信息。已经有一些了,我在模板 thankyou.php 中找到了它们。 但是我需要额外的 div 来添加一个名为 "Trusted Shops".

的工具

所以我尝试了以下代码:

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">mein.kunde@mail.de</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>
    ';
}

问题是,我没有从 $order 获取数据。 我收到以下错误:

Fatal error: Uncaught Error: Call to a member function get_order_number() on null in....

我尝试添加此代码,但没有帮助:

global $woocommerce, $post;
$order = new WC_Order($post->ID);

少了什么?我如何从 $order 获取数据?

还有奖励:我怎样才能得到预计的交货日期? ;)

我明白了!

我需要更改:

function trusted_shops_thankyou( $order_id )

至:

function trusted_shops_thankyou( $order )