• Resolved zkrahn

    (@zkrahn)


    Hello,

    I am trying to perform actions when a user registers, specifically when they register using a specific forminator form.

    I’ve tried using the hook forminator_custom_form_submit_field_data, however with this method I cannot get the user ID, and I’m not even sure the user has been created at that point.

    I have also tried using the hook user_register, and setting user meta on the form submission. However, it seems that when the user_register is called, the user meta has not yet been set. Perhaps it’s just that Forminator firsts creates the user, then sets the user meta?

    Here’s the code for the above method:

    function dc_user_register_add_member($user_id){
        
        // Ensure WC Memberships is installed and active
        if ( ! function_exists( 'wc_memberships' ) ) {
            divic_log_debug('No memberships');
            return;
        }
        
        // Check if the membership should be created based on user meta
        
        $membership_on_register = get_user_meta($user_id, 'membership-on-register', true);
        
        if( !$membership_on_register ){
            divic_log_debug('Not member user created: ' . $membership_on_register);
            return;
        }
        
        divic_log_debug('Created membership');
    }

    When I run this code I get the “Not member user created” message, but I check and the user meta is definitely getting set.

    Any help would really be appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @zkrahn

    I hope you are doing well.

    Can you try the forminator_cform_user_registered?

    add_action('forminator_cform_user_registered', function($user_id){
    // your custom action 
    },1,20);

    forminator/library/modules/custom-forms/front/front-user-registration.php:246

    do_action( 'forminator_cform_user_registered', $user_id, $custom_form, $entry, $new_user_data['user_pass'], $submitted_data );

    Let us know if this works for you.
    Best Regards
    Patrick Freitas

    Thread Starter zkrahn

    (@zkrahn)

    Thanks so much, this worked!

    Now I’m also wondering if it’s also possible to add custom form options, perhaps either accessed through the $custom_form variable, or retrieved through the forms ID? Although this is quite a different subject from what I originally asked, so I could make a separate post for it if you’d like.

    The reason is that how I would currently have it set up is to simply check for a specific form ID, and then if it’s a match I run some code. It would be nice, however, to have the admins be able to easily select an option for any form to have the code run, and this would make it much more flexible and maintainable.

    Thanks again so much for the excellent support!

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello there @zkrahn

    In the action hook shared above by Patrick, there is a $custom_form argument which is basically the form ID, so you can be specific on that.

    Warm regards,
    Dimitris

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘User Registration Hook’ is closed to new replies.