我想在我的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
获取数据?
奖金:我怎样才能得到预计的交货日期? ;)
答案 0 :(得分:1)
我明白了!
我需要改变它:
function trusted_shops_thankyou( $order_id )
到那个:
function trusted_shops_thankyou( $order )