Okay
  Public Ticket #3782295
Conversation Email Notification
Closed

Comments

  •  8
    Miguel Zenha started the conversation

    Hi Stefan!

    Is it possible for the admin to receive an email with the conversation message initiated by the clients ?

     I've done some tests but I think that the admin must enter the wordpress admin area to check if there are new messages. 

    It would be a great feature if an email was sent every time a new message (or quote request, etc.) was submitted.

    Best regards and thanks

  •  2,435
    WebWizards replied

    Hello Miguel,

    The plugin does have a feature for this, through the built in "new message / conversation" email. 

    Please make sure that you have that enabled, under WooCommerce -> Settings -> Emails:

    4153309545.png

     

    If you do have that enabled but do not receive the email, I would suggest to check with a mail logging plugin to see if the email exists in the log or not: https://wordpress.org/plugins/wp-mail-logging/

     

    Kind regards,

    Stefan

  •  8
    Miguel Zenha replied

    Hi Stefan!

    Thank you!
    Is there any way I can add more email recipients to the "New message/conversation" email?


    1724849518.png

    Right now, I think that it only goes to the wordpress admin, but I wanted to add one more email.

    Best regards and thanks
  •  2,435
    WebWizards replied

    Hi again Miguel,

    Yes, you can add the following PHP code snippet to control which addresses receive that email:

    add_filter('b2bking_recipient_new_message', function($recipient, $conversationid){
    	return '[email protected], [email protected]';
    }, 10, 2);
    add_filter('b2bking_recipient_new_message_quote', function($recipient, $conversationid){
    	return '[email protected], [email protected]';
    }, 10, 2);

    Replace email1, email2 etc with your own email addresses that should receive it. You can add more addresses by just adding them using a comma (,).

     

    The code snippet can be added to functions.php or any snippets plugin,

     

    Kind regards,

    Stefan

  •  8
    Miguel Zenha replied

    Hi Stefan,

    I have another question about this feature.

    My quote request form has a select field, that has the id b2bking_field_1169, and has 3 options: Generic, Warranty, Other.

    I want to change the email addresses which receive the email, based on the option that was selected on the field.

    However, my code does not seem to work:

    function get_recipient_emails_by_field() {
        $default_emails = '[email protected]';
        $warranties_emails = '[email protected]';
        
        // Verifica se o campo existe e tem o valor esperado
        if (isset($_POST['b2bking_field_1169']) && 
            sanitize_text_field($_POST['b2bking_field_1169']) === 'Warranty') {
            return $warranties_emails;
        }
        
        return $default_emails;
    }
    add_filter('b2bking_recipient_new_message', function($recipient, $conversationid){
        return get_recipient_emails_by_field();
    }, 10, 2);
    add_filter('b2bking_recipient_new_message_quote', function($recipient, $conversationid){
        return get_recipient_emails_by_field();
        
    }, 10, 2);


    I think that the $_POST['b2bking_field_1169'] is not fetching anything. Maybe I have to pass the conversation id in order to get the field?


    Can you please tell me what's wrong with the code?

    Best regards and thanks

  •  2,435
    WebWizards replied

    Hi Miguel,

    Generally the code appears correct, but I think I see the issue.

     

    That's based on the "name" property, not ID, therefore I believe it should be

    $_POST['b2bking_custom_field_1169'] 

    (not b2bking_field_1169)

     

    Let me know if that works please,

    Stefan