douque8861 2018-02-09 07:14
浏览 56
已采纳

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

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条回答 默认 最新

  • dsgdg54ef4365 2018-02-09 07:42
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏