这个问题与user_register 挂钩
我需要在 woocommerce 的用户注册表单上添加一些额外的字段,我使用了自定义用户注册字段 - WooCommerce 插件
我的问题是如何使用 add_action 钩子访问这些添加字段的值?
这是我到目前为止所做的,
add_action( 'user_register', 'new_contact', 10, 3 );
function new_contact( $user_id ) {
if ( isset( $_POST['first_name'] ) )
update_user_meta($user_id, 'first_name', $_POST['first_name']);
$customer = new WC_Customer( $user_id );
echo $customer;
wp_die();
}
以下是回显的输出:
{
"id":12,
"date_created":{"date":"2020-07-27 16:58:52.000000","timezone_type":1,"timezone":"+00:00"},
"date_modified":null,
"email":"c@hotmail.com",
"first_name":""
,"last_name":"",
"display_name":"c",
"role":"customer",
"username":"c",
"billing":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","postcode":"","country":"","state":"","email":"","phone":""},
"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","postcode":"","country":"","state":""},
"is_paying_customer":false,
"meta_data":[
{"id":516,"key":"afreg_additional_1564","value":"c"},
{"id":517,"key":"afreg_additional_1565","value":"c"},
{"id":518,"key":"afreg_additional_1566","value":"c"},
{"id":519,"key":"afreg_additional_1555","value":"c"},
{"id":520,"key":"afreg_additional_1556","value":"c"},
{"id":521,"key":"afreg_additional_1557","value":"c"},
{"id":522,"key":"afreg_additional_1558","value":"California"},
{"id":523,"key":"afreg_additional_1559","value":"c"},
{"id":524,"key":"afreg_additional_1560","value":"6181001010"},
{"id":525,"key":"afreg_additional_1561","value":"c"},
{"id":526,"key":"_yoast_wpseo_profile_updated","value":"1595894332"}
]
}
我可以看到我添加的自定义字段存储在“meta_data”中
我如何将每个值存储在变量中?