0

I'm using dokan multivendor, can anyone knows the simple script of forcing all the newly registered to enable the selling mode? when you register as a seller, the selling mode is automatically on, when you register as a customer, the selling mode is off. What I wanted is to have a script of control, for example, if the register register as a contributor or editor, it will automatically make the selling mode "ON".

they have this code:

 add_action('gform_post_submission_1', 'marvel_update_dokan_enable_selling', 10, 2);
 function marvel_update_dokan_enable_selling() {
     $current_user = wp_get_current_user();
     $current_user_id = $current_user->ID;

     update_user_meta( $current_user_id, 'dokan_enable_selling', 'yes' );

 }

but this is for gravity forms

2

1 Answer 1

0

I would hook into user_register similarly to how you hooked into gform_post_submission_1 before. For example:

add_action( 'user_register', 'awesome_function_name', 10, 1 );
function awesome_function_name( $user_id ) {
    // Conditional logic for testing user role
    update_user_meta( $user_id, 'dokan_enable_selling', 'yes' );
}

For your conditional logic, if you're trying to make every role do this except customer I typically use the following function which I don't remember where I got so I can't credit them unfortunately.

function check_user_role( $role, $user_id = null ) {
    if( is_numeric( $user_id ) ) {
        $user = get_userdata( $user_id );
    } else {
        $user = wp_get_current_user();
    }

    return in_array( $role, (array)$user->roles );
}

So your action above would be modified to:

add_action( 'user_register', 'awesome_function_name', 10, 1 );
function awesome_function_name( $user_id ) {
    if( !check_user_role( 'customer', $user_id ) ) {
        update_user_meta( $user_id, 'dokan_enable_selling', 'yes' );
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.