我似乎对上的自定义字段有问题register form (与WooCommerce一起使用)
function my_account_send_form_post_data( ) {
$email = $_POST["email"];
$firstname = $_POST["billing_first_name"];
$lastname = $_POST["billing_last_name"];
$api = $this->get_api();
if ( ! $api ) {
return false;
}
if ( isset( $_POST[\'mailchimp-subscribe\'] ) && \'yes\' == $_POST[\'mailchimp-subscribe\'] ) {
$list_id = $this->get_option( \'wc_mailchimp_list_id\' );
$double_optin = $this->get_option( \'wc_mailchimp_double_optin\' ) == \'yes\';
$api->my_account_subscribe_to_list( $list_id, $firstname, $lastname, $email);
}
return true;
}
/**
* Subscribe to Mailchimp via account registration on my-account page
* @param string $list_id
* @param string $firstname
* @param string $lastname
* @param string $email
**/
public function my_account_subscribe_to_list( $list_id, $firstname, $lastname, $email)
{
$data = array(
\'id\' => $list_id,
\'email\' => array( \'email\' => $email ),
\'merge_vars\' => array(
\'FNAME\' => $firstname,
\'LNAME\' => $lastname,
),
\'double_optin\' => false,
\'update_existing\' => true,
);
$response = $this->perform_request( \'/lists/subscribe.json\', $data );
$response = wp_remote_retrieve_body( $response );
echo print_r($response, true);
if ( is_wp_error( $response ) ) {
return false;
}
$response = json_decode( $response, true );
echo print_r($response, true);
if ( isset( $response[\'status\'] ) && \'error\' == $response[\'status\'] ) {
return false;
}
return true;
}
正如您所看到的
my_account_subscribe_to_list 处理自定义信息的提交,并将
print_r 回应。
首次尝试注册时,您将正确注册到WordPress,但从未处理自定义数据。
第二次尝试使用与第一次尝试相同的注册信息注册帐户时。您将收到一个错误,即注册信息已在使用中(如怀疑的那样)。但您还将收到$response 因此,正在处理自定义字段和数据。
最合适的回答,由SO网友:odinp123 整理而成
在文档中register_form 是指user_register 挂钩下方,用于:
此操作挂钩允许您在新用户添加到数据库后立即访问其数据。用户id作为参数传递给hook。
通常,此挂钩用于保存自定义注册表传递的其他用户元。
正在更改register_form 到user_register 修复了该问题,并在注册完成时让我执行其他数据处理