Woocommerce-Get Value of Custom Field in Checkout

核能气质少年 提交于 2019-12-11 16:19:04

问题


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.

Any help is appreciated.


回答1:


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.

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 );`

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



来源:https://stackoverflow.com/questions/48700542/woocommerce-get-value-of-custom-field-in-checkout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!