Woocommerce-在结帐中获取自定义字段的价值

问题描述:

我有一个灵活的问题,我没有得到任何答案。我在Woocommerce Checkout字段中使用 Checkout Field Editor添加了一个自定义字段。

I have a nimble question that i am not getting any answer of. I have added a custom field using "Checkout Field Editor" in Woocommerce Checkout fields. The field is given below and seems to be working fine.

 <input class="input-text " name="wc_order_field_7542" id="wc_order_field_7542" placeholder="Pickup Date" value="" type="text">

但是,现在我正在开发一个插件,想要在此特定字段中输入值,并且不能似乎能弄清楚。对于其他字段,我只是在执行以下操作,就像我在计费电子邮件中一样,它正在工作:

However, now I am working on a plugin and want to get value inputted in this specific field and cannot seem to figure out. For the other fields I am simply doing the following as I am doing for "billing email" and it is working:

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();
}

我确定我会忘记某些事情,而没有做正确的事情。

I am sure I am forgetting something and not doing something right.

感谢您的帮助。

您的插件,因为 $ this-> order 似乎是 WC_Order 对象的实例,因此您将尝试使用 $ this-> order-> get_id()获取订单ID。

For a custom field in your plugin, as $this->order seems to be the instance of the WC_Order object, you will try to use $this->order->get_id() to get the order ID.

现在,您可以使用WordPress get_post_meta()尝试以下操作以获取自定义字段值:

Now you can try something using WordPress get_post_meta() to get your custom field value, this way:

$pickup_date = get_post_meta( $this->order->get_id(), 'wc_order_field_7542', true );`




但是签入 wp_postmeta 您的订单应存在的 meta_key 'wc_order_field_7542'的数据库表。如果不是这种情况,则必须找出正确的 meta_key 来处理提货日期数据...

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...