Home Forums Newsletter Plugin Support I created function to add customer into my subcriber list

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #345563
    MOHAMMAD ALI
    Participant

    Dear

    I am using a funciton below

    function meetalgo_add_to_newsletter_plugin($user_id) {
    error_log(‘🟡 Called function: meetalgo_add_to_newsletter_plugin()’);

    if (!class_exists(‘NewsletterSubscription’)) {
    error_log(‘🔴 NewsletterSubscription class not found.’);
    return;
    }

    $subscription = NewsletterSubscription::instance();

    if (!function_exists(‘Newsletter’)) {
    error_log(‘🔴 Newsletter function not found.’);
    return;
    }

    $user = get_userdata($user_id);
    if (!$user) {
    error_log(‘🔴 User not found.’);
    return;
    }

    $email = $user->user_email;
    $name = $user->first_name;

    $user_record = Newsletter()->get_user($email);

    if ($user_record) {
    if ($user_record->status === ‘U’) {
    error_log(“⛔ $email is unsubscribed. Skipping.”);
    return;
    } elseif ($user_record->status !== ‘C’) {
    Newsletter()->update_user($user_record->id, [‘status’ => ‘C’]);
    error_log(“✅ $email updated to confirmed.”);
    return;
    }

    error_log(“ℹ️ $email already confirmed.”);
    return;
    }

    // Subscribe new user to List ID 1 (adjust as needed)
    $result = $subscription->subscribe([
    ’email’ => $email,
    ‘name’ => $name,
    ‘status’ => ‘C’,
    ‘lists’ => [1] // Replace 1 with your actual list ID
    ], [‘send’ => false]);

    if (is_wp_error($result)) {
    error_log(‘❌ Newsletter subscribe error: ‘ . $result->get_error_message());
    } else {
    error_log(“✅ Newsletter: $email subscribed successfully.”);
    }
    }

    I call to add list into my subscriber when I call function this is working well

    $result = $subscription->subscribe([
    ’email’ => $email,
    ‘name’ => $name,
    ‘status’ => ‘C’,
    ‘lists’ => [1] // Replace 1 with your actual list ID
    ], [‘send’ => false]);

    but user not add into my subscriber list I don’t know where the problem is

    #345645
    Michael
    Keymaster

    Hello,

    unfortunately we cannot give support on custom code. A skilled devleoper should be able to help you on these matters.

    Michael

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.