Woocommerce-在结帐时获取自定义字段的价值
Woocommerce-Get Value of Custom Field in Checkout
我有一个灵活的问题,但我没有得到任何答案。我在 Woocommerce 结帐字段中使用 "Checkout Field Editor" 添加了自定义字段。该字段如下所示,似乎工作正常。
<input class="input-text " name="wc_order_field_7542" id="wc_order_field_7542" placeholder="Pickup Date" value="" type="text">
但是,现在我正在开发一个插件,想要在这个特定字段中输入值,但似乎无法弄清楚。对于其他字段,我只是像为 "billing email" 所做的那样执行以下操作并且它正在工作:
public function get_billing_email() {
$billing_email = $this->order->billing_email;
return apply_filters( 'xc_woo_cloud_print_billing_email', $billing_email, $this );
}
public function billing_email() {
echo $this->get_billing_email();
}
我确定我忘记了一些事情并且没有做正确的事情。
感谢任何帮助。
对于插件中的自定义字段,由于 $this->order
似乎是 WC_Order
对象的实例,您将尝试使用 $this->order->get_id()
来获取订单 ID。
现在您可以尝试使用 WordPress get_post_meta()
来获取您的自定义字段值,这样:
$pickup_date = get_post_meta( $this->order->get_id(), 'wc_order_field_7542', true );`
But check in wp_postmeta
database table for the meta_key
'wc_order_field_7542'
that should exist for your orders. If it's not the case, you will have to find out the correct meta_key
that is handling the pickup date data...
我有一个灵活的问题,但我没有得到任何答案。我在 Woocommerce 结帐字段中使用 "Checkout Field Editor" 添加了自定义字段。该字段如下所示,似乎工作正常。
<input class="input-text " name="wc_order_field_7542" id="wc_order_field_7542" placeholder="Pickup Date" value="" type="text">
但是,现在我正在开发一个插件,想要在这个特定字段中输入值,但似乎无法弄清楚。对于其他字段,我只是像为 "billing email" 所做的那样执行以下操作并且它正在工作:
public function get_billing_email() {
$billing_email = $this->order->billing_email;
return apply_filters( 'xc_woo_cloud_print_billing_email', $billing_email, $this );
}
public function billing_email() {
echo $this->get_billing_email();
}
我确定我忘记了一些事情并且没有做正确的事情。
感谢任何帮助。
对于插件中的自定义字段,由于 $this->order
似乎是 WC_Order
对象的实例,您将尝试使用 $this->order->get_id()
来获取订单 ID。
现在您可以尝试使用 WordPress get_post_meta()
来获取您的自定义字段值,这样:
$pickup_date = get_post_meta( $this->order->get_id(), 'wc_order_field_7542', true );`
But check in
wp_postmeta
database table for themeta_key
'wc_order_field_7542'
that should exist for your orders. If it's not the case, you will have to find out the correctmeta_key
that is handling the pickup date data...