Public Ticket #3353499

E-Mail after changing role?

Closed
Comments
7 Tickets 6
Wolfgang Saul started the conversation 3 years ago on April 21, 2023 at 5:55am

Hello!  I have the following question: when a customer's user role is changed - manually or automatically - does he get a message? (Email) Can I set this up? Thank you and greetings! Wolfgang

2,762
KingsPlugins replied 3 years ago on April 21, 2023 at 10:58am

Hi Wolfgang,


Just for clarity, I mention our plugin doesn't use WP roles (such as 'subscriber', 'administrator', 'editor' etc). Our plugin uses its own groups instead.

Users would not normally get a message when their group is changed.

That's because groups are not really 'public' by default (they're more of a private way for the admin to organize users, it shouldn't necessarily be visible or known to the user).


We may be able to write a code snippet that does that, but it is quite complex. Can you give us more information about what you are trying to set up or achieve in your store? I wonder if we have a different way of doing it or some simple way of setting this up,


Kind regards,

Stefan

7 Tickets 6
Wolfgang Saul replied 3 years ago on April 21, 2023 at 11:07am

Hello! When a customer has multiple orders or reached a certain amount, then I want to automatically change their user role from "Customer" to "Regular Customer" with 5% discount. Of course, the customer should be informed about this by e-mail.  According to the motto: "Congratulations! From now on you are a regular customer and get 5% discount on every item!"

2,762
KingsPlugins replied 3 years ago on April 25, 2023 at 10:40pm

Hi Wolfgang,

To achieve that, you can:

1) Go to B2BKing -> Group Rules and configure a group rule based on "TOTAL SPENT", for example:

8080090754.png

2)

Add this PHP code snippet to your site:

add_action('b2bking_apply_group_rule', function($rule_id, $howmuch, $newgroup, $user_id){
    $email_sent = get_user_meta($user_id,'group_email_sent', true);
    if ($email_sent !== 'yes'){
        $user = new WP_User($user_id);
        $condition = get_post_meta($rule_id, 'b2bking_rule_applies', true);
        if ($condition === 'order_value_total'){
            $total_orders_amount = $user->get_total_spent();
            if ($total_orders_amount >= $howmuch){
                $recipient = $user->user_email;
                $message = 'Congratulations! From now on you are a regular customer and get 5%  discount on every item!';
                do_action( 'b2bking_new_message', $recipient, $message, get_current_user_id(), 0 );
                update_user_meta($user_id,'group_email_sent', 'yes');
            }
        }
    }
    
}, 10, 4);

A PHP snippet can be added to functions.php, or by following our guide here: https://b2bkingplugin.com/docs/how-to-add-a-snippet-php-or-js/

It should then automatically send the message configured in the snippet to the user when they get promoted to the new group.

Kind regards,

Stefan

Sign In