实际上我正在创建一个新的插件,我想获得order number
和所有其他细节,但现在只是order number
。为此我使用以下代码,我从Stackoverflow获得过去的答案。
add_action( 'wp_head', 'get_order_num' );
function get_order_num($order_id) {
global $woocommerce, $order;
$order = new WC_Order($order->ID);
print_r($order);
die();
//to escape # from order id
$order_id = trim(str_replace('#', '', $order->get_order_number()));
echo ($order_id);
}
但这显示我的结果为0
当我对它执行print_r时,这是显示的结果
WC_Order Object
(
[order_type] => simple
[id] => 0
[post] =>
[order_date] =>
[modified_date] =>
[customer_message] =>
[customer_note] =>
[post_status] =>
[prices_include_tax] =>
[tax_display_cart] => excl
[display_totals_ex_tax] => 1
[display_cart_ex_tax] => 1
[formatted_billing_address:protected] =>
[formatted_shipping_address:protected] =>
)
我知道这并没有向我显示数组中的订单号。我想知道如何在
中展示它答案 0 :(得分:2)
您可以挂钩woocommerce_thankyou_order_id
。它的工作原理如下:
function my_beautiful_hook($order_id)
{
//Do some magic here
}
add_action('woocommerce_thankyou_order_id','my_beautiful_hook')