• Resolved playdiune

    (@playdiune)


    hello,

    how can I send an email to affiliate after Donne a payment ?

    I want to advise him the payment has been Donne.

    tanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support mbrsolution

    (@mbrsolution)

    Thank you for reaching out to us.

    I want to advise him the payment has been Donne.

    You will have to manually send an email to the person who earned the commission, letting them know that the money has been paid into their account. We currently don’t have a feature to cater for your requirement.

    Our plugin currently has the following message affiliate_commission_notification_email available. And you can also use some tags in the email body. The following documentation can help.

    https://wpaffiliatemanager.com/affiliates-manager-email-tags/

    Let me know if the information above helps you in any way.

    Kind regards.

    Thread Starter playdiune

    (@playdiune)

    I wrotte this but with no success

    add_action('wpam_payment_saved', 'notificar_afiliado_pagamento', 10, 1);

    function notificar_afiliado_pagamento($payment_data) {
    // Obter detalhes do pagamento
    $affiliate_id = $payment_data['affiliateId'];
    $payment_amount = $payment_data['amount'];
    $payment_date = $payment_data['date'];
    $payment_reference = isset($payment_data['txnId']) ? $payment_data['txnId'] : 'Sem referência';

    // Obter informações do afiliado
    $affiliate = wpam_get_affiliate($affiliate_id);
    $affiliate_email = $affiliate->email;
    $affiliate_name = $affiliate->firstName . ' ' . $affiliate->lastName;

    // Montar o conteúdo do e-mail
    $subject = 'Pagamento Recebido - Liga dos Vencedores';
    $message = "
    <html>
    <head>
    <style>
    body { font-family: Arial, sans-serif; color: #333; }
    </style>
    </head>
    <body>
    <h2>Olá, $affiliate_name!</h2>
    <p>Temos o prazer de informar que o pagamento do seu saldo foi registrado com sucesso!</p>
    <p><strong>Detalhes do pagamento:</strong></p>
    <ul>
    <li><strong>Valor:</strong> R$ $payment_amount</li>
    <li><strong>Data do pagamento:</strong> $payment_date</li>
    <li><strong>Referência:</strong> $payment_reference</li>
    </ul>
    <p>Obrigado por fazer parte da Liga dos Vencedores!</p>
    <p>Se tiver alguma dúvida, entre em contato conosco.</p>
    </body>
    </html>
    ";

    // Cabeçalhos do e-mail
    $headers = array(
    'Content-Type: text/html; charset=UTF-8',
    'From: Liga dos Vencedores <[email protected]>'
    );

    // Enviar o e-mail
    wp_mail($affiliate_email, $subject, $message, $headers);
    }

    Why this do not work ?

    • This reply was modified 1 year, 5 months ago by playdiune.
    • This reply was modified 1 year, 5 months ago by playdiune.
    Thread Starter playdiune

    (@playdiune)

    Good afternoon,
    After researching the plugin code, I managed to get an email sent after a manual payment was made to affiliates.

    Here are the necessary changes for everyone who feels the same need:

    Edit the file: affiliates-manager/source/Util/JsonHandler.php and change the function public function addTransaction($request)

    Add this code

    // **Disparar o gancho para o tipo 'payout'**
    if ($type === 'payout') {
    do_action('wpam_payout_processed', $affiliateId, $amount, $description);
    }

    Just after the code line:

    $db→getTransactionRepository()→insert($transaction);

    And then just add this function to your functions.php or mu-plugin



    add_action('wpam_payout_processed', 'notificar_afiliado_pagamento', 10, 3);

    function notificar_afiliado_pagamento($affiliateId, $amount, $description) {

    global $wpdb;

    // Obter o ID do utilizador do WordPress associado ao afiliado

    $table_name = $wpdb->prefix . 'wpam_affiliates';

    $userId = $wpdb->get_var($wpdb->prepare(

    "SELECT userId FROM $table_name WHERE affiliateId = %d",

    $affiliateId

    ));

    if (!$userId) {

    error_log("Nenhum utilizador do WordPress encontrado para o ID do afiliado: $affiliateId");

    return;

    }

    // Obter os dados do usuário no WordPress

    $affiliate = get_userdata($userId);

    if (!$affiliate) {

    error_log("Utilizador do WordPress não encontrado para o ID do afiliado: $affiliateId (User ID: $userId)");

    return;

    }

    // Preparar os dados

    $user_name = $affiliate->display_name; // Nome do afiliado

    $to = $affiliate->user_email;

    $subject = "Pagamento Enviado";

    // Transformar o valor para positivo e adicionar símbolo de €

    $formatted_amount = number_format(abs($amount), 2, ',', '.') . ' €';

    // Obter a data atual

    $payment_date = current_time('mysql'); // Data no formato Y-m-d H:i:s

    // Corpo do e-mail com a data incluída

    $body = '

    <html>

    <head>

    <style>

    body {

    font-family: Arial, sans-serif;

    }

    </style>

    </head>

    <body>

    <table role="presentation" style="width: 100%; border: none; background-color: #f4f4f4;">

    <tr>

    <td style="text-align: center;">

    <!-- Imagem de cabeçalho -->

    <img src=" an image you want.jpg" alt="Pagamento Enviado" style="width: 100%; max-width: 600px;">

    </td>

    </tr>

    <tr>

    <td style="padding: 20px;">

    <!-- Conteúdo principal do e-mail -->

    <h2>Detalhes do Pagamento Enviado</h2>

    <p><strong>Nome do Afiliado:</strong> ' . $user_name . '</p>

    <p><strong>Valor Pago:</strong> ' . $formatted_amount . '</p>

    <p><strong>Descrição:</strong> ' . $description . '</p>

    <p><strong>Data:</strong> ' . $payment_date . '</p>

    </td>

    </tr>

    <tr>

    <td style="background-color: #333; color: #fff; padding: 20px;">

    <!-- Rodapé do e-mail -->


    </td>

    </tr>

    </table>

    </body>

    </html>

    ';

    // Definir os cabeçalhos

    $headers = array(

    'Content-Type: text/html; charset=UTF-8',

    'From: Nome do Remetente <[email protected]>',

    'Reply-To: [email protected]'

    );

    // Enviar o e-mail

    if (wp_mail($to, $subject, $body, $headers)) {

    error_log("E-mail de pagamento enviado com sucesso para $to.");

    } else {

    error_log("Erro ao enviar e-mail de pagamento para $to.");

    }

    }

    Of course, you can define the email header, body and footer however you want.

    Hope i can help all of you

    Plugin Author affmngr

    (@affmngr)

    Hi, Thanks for the code.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Send email after payment’ is closed to new replies.