嘿,伙计们,上面的代码只做了一些更改。看看这个,它对我有用。注意:请将LIST\\u ID更改为您的klaviyo的LIST ID,并从您的klaviyo帐户中获取一个私钥并将其添加到private\\u API\\u key
function send_coupon_to_freshly_registered_user($user_id) {
$user = get_user_by(\'id\',$user_id); //new line
$user_email = stripslashes($user->user_email); //changed line
$emailecho = "".$user_email."";
$xxx = \'{"profiles":[{"email":"\'.$emailecho.\'"}]}\';
$xxx = json_decode($xxx);
$yyy = json_encode($xxx);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://a.klaviyo.com/api/v2/list/LIST_ID/members?api_key=PRIVATE_API_KEY",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\\"profiles\\":[{\\"email\\":\\"".$emailecho."\\"}]}",
CURLOPT_HTTPHEADER => [
"Accept: application/json",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err . "cmdskcmdsl";
} else {
echo $response;
}
}
add_action(\'user_register\', \'send_coupon_to_freshly_registered_user\', 10, 1);