如何从订单中访问自定义字段woocommerce

如何从订单中访问自定义字段woocommerce

问题描述:

我有很多自定义字段是我在订单中创建的,我现在试图在订单完成时在谢谢页面上访问它们。如何从订单中访问自定义字段woocommerce

我看过this回应,但它不适用于我。我做了一个var dump来查看$order->order_custom_fields里面有什么,但我刚刚得到string(0) ""

我正在编辑这个文件order-details-customer.php如何访问我的自定义字段?

这里是我创造

 woocommerce_form_field('destination_state', array(
     'type'   => 'text', 
     'class'   => array('destination_state form-row-first'), 
     'label'   => __('State'), 
     'required'  => true, 
     ), $checkout->get_value('destination_state')); 

有点搜索后,只是逻辑思维我想通了,这是很容易的自定义字段的例子。

echo '<p>' . get_post_meta( $order->id, 'Date Collection', true) . '</p>';