【发布时间】:2021-08-09 00:31:45
【问题描述】:
我想为每个 woocommerce 订单输入 digits_phone 元键的值以输入为 billing_phone。
我想出了类似的方法,但它不起作用:
//Automatically add the digits phone number of the user, to woocommerce orders for every order
add_filter('woocommerce_checkout_posted_data', 'dg_manipulate_checkout_posted_data');
function dg_manipulate_checkout_posted_data ($data) {
$data['billing_phone'] =['digits_phone'];
return $data;
}
谁能帮我解决这个问题?
【问题讨论】:
-
嗨,:) 你从哪里得到digits_phone?假设您使用插件来管理数字,我想您应该能够通过调用
get_user_meta( $current_user->ID, 'digits_phone' , true );来获取数据 ... -
嗨@giulp。是的digits_phone 由digits 插件管理。那么我应该如何编辑代码以从用户元中实际获取
digits_phone并将其放入 woocommerce 订单的billing_phone中?它必须是这样的吗?add_filter('woocommerce_checkout_posted_data', 'dg_manipulate_checkout_posted_data'); function dg_manipulate_checkout_posted_data ($data) { $data['billing_phone'] = get_user_meta( $current_user->ID, 'digits_phone' , true );; return $data; } -
您需要通过
$current_user = wp_get_current_user();获取当前用户数据 -
感谢您的帮助。实际上我是一个新手,并不真正知道如何完全使用这些代码。您能否以某种方式将您发送的代码与我在此问题中作为答案提出的初始代码结合起来或更正它?
标签: wordpress woocommerce hook-woocommerce meta-key