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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器