Okay
  Public Ticket #2844769
Email new account
Closed

Comments

  • Yvon started the conversation

    I have 2 kind of clients in my webshop:

    1. Regular clients
    2. B2B clients 

    1. Regular clients can directly use their account, but 2. B2B clients needs to get an approval first first. 

    When a client signs up, there is only 1 email in Woocomerce - Settings - Emails:
    "New account" 

    This email is sent to 1. Regular clients and 2. B2B clients, but I want to have a different email template for that. How can I add another email? 

    Thank you in advance 

  •  2,217
    WebWizards replied

    Hi Yvon,

    Thank you for purchasing the plugin, 


    1)

    The way it works by default is that there is only 1 email (this is a standard WooCommerce email, not from our plugin). And our plugin adds an extra text for users that need manual approval, notifying them. You can also edit this text.

    7988144860.png

    This text can be changed by using a filter. It's as simple as adding this code snippet:

    add_filter('b2bking_new_account_email_approval_notification', function($text){
        return 'Your Text Here';
    });

    To Add A Snippet: https://woocommerce-b2b-plugin.com/docs/how-to-add-a-snippet-php-or-js/


    2)

    If you want to have an entirely different email / template, that can be achieved but it's a lot harder and requires custom coding work.

    I think the way to do it would be to create 2 php templates and then filter which one is the one that's loaded (via a filter such as 'woocommerce_locate_template'). Some more info: https://stackoverflow.com/questions/59097318/how-to-set-a-woocommerce-email-template-as-default-for-all-emails

    However, this is complex custom work and it's not something we can do directly for you as part of support - however if you or your team is familiar with coding, I'm happy to provide any technical info you would need.


    Kind regards,

    Stefan

  • Yvon replied

    Thank you for your reply.

    If we go for option 1; can we also change the location of the text? I want to display this more in the beginning of the default email. 

    Thank you in advance, 

  •  2,217
    WebWizards replied

    Hi Yvon,

    I checked, there are 2 hooks: footer and header.

    If you'd like, you can place it at the beginning of the email by using the header hook.

    8999063344.png


    To do that, add this snippet to your site:

    global $b2bking_public;
    remove_action( 'woocommerce_email_footer', array($b2bking_public,'b2bking_modify_new_account_email'), 10, 1 );
    add_action( 'woocommerce_email_header', function($header, $email){
        if ( $email->id === 'customer_new_account' ) {
            $user = get_user_by('email', $email->user_email);
            $approval_needed = get_user_meta($user->ID, 'b2bking_account_approved', true);
            if ($approval_needed === 'no'){
                ?>
                <p>
                    <?php
                    $text = esc_html__('Attention! Your account requires manual approval. Our team will review it as soon as possible. Thank you for understanding.', 'b2bking');
                    $text = apply_filters('b2bking_new_account_email_approval_notification', $text );
                    echo $text;
                    ?>
                </p>
                <?php
            }
        }
    }, 100, 2);

    With the above snippet, you no longer need the previous snippet, you can directly change the text in the above.


    Other than this, I can't control the position further as there are just the 2 hooks. For more control you would need to modify the .php template .


    Kind regards,

    Stefan

  • Yvon replied

    Ok thank you. 1 last question: Can we remove the existing / default content (inside blue box) ?

  •  2,217
    WebWizards replied

    You could modify that text by using a translation plugin such as Loco Translate and creating a translation (even if you are not actually changing the language). You can create an English translation if the site language is English, and that simply means your translation overwrites the default texts.


    With Loco I set translated that line for the WooCommerce plugin:


    6295188827.png


    The result is that the line is replaced by the "-" symbol in the email

    5387186594.png


    You can find a guide for how to translate WooCommerce with Loco Translate here:

    https://docs.woocommerce.com/document/woocommerce-localization/


    Kind regards,

    Stefan

  • Yvon replied

    One other question. Where can we edit this email? I can't access it with the same hook. 

  •  2,217
    WebWizards replied

    Hi,

    This email is added by our plugin,


    You can modify it in 2 ways:

    1.  Add a snippet such as:

    add_action( 'woocommerce_email_header', function($header, $email){
        if ( $email->id === 'b2bking_your_account_approved_email' ) {
                ?>
                <p>
                    <?php
                    $text = esc_html__('Your text here', 'b2bking');
                    echo $text;
                    ?>
                </p>
                <?php
            }
    }, 100, 2);
    

    Effect:

    8784780236.png


    2. Copy wp-content/plugins/b2bking/emails/templates/your-account-approved-email-template.php 

    to your theme folder (such as wp-content/themes/storefront/)

    Then you can modify it directly under the theme folder.


    Kind regards,

    Stefan