• Resolved Kokomo

    (@kokomoweb)


    Hey there,

    I figured out how to edit the admin notification email using the wpmem_notify_addr filter, but I would like for the admin email to be sent to different email addresses depending on what is filled in a field in the registration form. Is there a way to use the value of a field as a variable in that filter?

    Thank-you,

    Thierry

    https://www.ads-software.com/plugins/wp-members/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    That particular filter handles only the email address the admin notification goes to. Nothing else goes to the filter function.

    So… you could build conditional tests if you were checking the post values with $_POST, and that might be the simplest approach.

    However, you could use the wpmem_notify_filter. While it might seem far more complex and intimidating, it’s actually a very powerful filter because pretty much every element in the admin notification email goes through this filter. It’s the admin notification email equivalent to wpmem_email_filter (which handles the user emails).

    So with that filter, all of the user registration data can be passed to the filter and your notification email address can be changed based on the data provided.

    Hope that helps.

    Thread Starter Kokomo

    (@kokomoweb)

    Thanks for the reply, I think I understand that filter, is there an example somewhere of getting a custom field from the $field_data array? The documentation doesn’t go much into details about this.

    Thanks again

    Plugin Author Chad Butler

    (@cbutlerjr)

    The $field_data array is an array of the values the user posted in the form where the array key for the field is the field’s option name (which is the meta key).

    Your filter function needs to check the value of the field you are basing your condition on and then change the value of “admin_email” which is one of the email arguments being filtered (the $arr array).

    So within your filter function, if your field is ‘my_field’, the condition would look like:

    if ( 'some_value' == $field_data['my_field'] ) {
        $arr['admin_email'] = '[email protected]';
    }

    In the scope of a simple filter, that would look like this:

    add_filter( 'wpmem_notify_filter', 'my_notify_filter', 10, 3 );
    function my_notify_filter( $arr, $wpmem_fields, $fields ) {
        if ( 'some_value' == $field_data['my_field'] ) {
            $arr['admin_email'] = '[email protected]';
        }
        return $arr;
    }
    Thread Starter Kokomo

    (@kokomoweb)

    I figured it out, thanks for the help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Conditional statement by field for admin email notification’ is closed to new replies.