• Resolved johnelki

    (@johnelki)


    We would like the 1000+ members of our organisation to use Stripe for subscription payments. Only a few will have login ids and passwords. The pop-up payment window will nicely pre-fill the user’s name and email if logged in. Is there a workaround for this with members who can’t login? I tried the following kludge on our test site:

    get the member’s details;
    if not logged in, insert member as a new user and log the new user in (*);
    if login confirmed, proceed to payment.
    After successful payment delete this user

    Sadly this workaround didn’t work. I wondered if the variable $prefill_user_details in class_asp_pp_display.php was perhaps still set to false? Might I also know where the class AcceptStripePayments is defined?

    Thanks for an excellent plugin by the way.

    PS The URL above can be tested with:

    (No user id: Fred Smith) Member ID: 43541 Email: fs@fs.net
    (With user id: Joe Bloggs) Member ID: 43539 Email: jb@jb.net User: joe.bloggs Pass: abc123

    (*code used to log in new user – variables all pre-set of course) :
    // insert new user
    $id = wp_insert_user( array(
    ‘user_login’ => $user_name,
    ‘user_pass’ => ‘abc123’,
    ‘user_email’ => $email,
    ‘first_name’ => $member[‘first_name’],
    ‘last_name’ => $member[‘last_name’],
    ‘display_name’ => $full_name,
    ‘role’ => ”
    ));

    // log new user in
    wp_set_current_user($id,”);
    $user = get_user_by( ‘id’, $id );
    if( $user ) {
    wp_clear_auth_cookie();
    wp_set_current_user ( $user->ID );
    wp_set_auth_cookie ( $user->ID );
    do_action( ‘wp_login’, $user->user_login, $user );
    }

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Alexander C.

    (@alexanderfoxc)

    Hi.

    If all you want is to prefill customer name and email, you don’t need to create temporary users for that.

    You can hook to asp_ng_pp_data_ready filter and insert name and email if needed. Here’s an example code for this:

    function asp_ng_pp_data_ready_handler($data, $opts_arr) {
    
    //check if this is product ID 123. We need to prefill the data only for this product
    if ($data['product_id']!==123) {
    //not out product. Bailing.
     return $data;
    }
    //now let's check if name and email are already prefilled
    if (!empty($data['customer_name']) && !empty($data['customer_email'])) {
    //already prefilled. Let's bail
     return $data;
    }
    //now we can prefill our data. You can take those from $_POST or anywhere you prefer. In this example we'll just assign them.
    $name = 'Doe John';
    $email = 'blah@example.com';
    
    $data['customer_name'] = $name;
    $data['customer_email'] = $email;
    
    return $data;
    }
    
    add_filter ('asp_ng_pp_data_ready', 'asp_ng_pp_data_ready_handler', 10, 2);
    Thread Starter johnelki

    (@johnelki)

    Hi Alexander
    Many thanks for your very prompt reply. Forgive two really dumb questions: firstly what is $opts_arr for? Is it an optional array for passing data in to the function? and secondly: how is the $data, which is returned from the function, passed to the product shortcode – or am I barking up the wrong tree?

    Plugin Contributor Alexander C.

    (@alexanderfoxc)

    what is $opts_arr for?

    It’s solely for compatibility with some legacy code. It is no longer being used, so you can safely ignore it.

    how is the $data, which is returned from the function, passed to the product shortcode

    It is using WP’s apply_filters() function https://developer.wordpress.org/reference/functions/apply_filters/

    Here’s how it is being used in the code:

    $data = apply_filters( 'asp_ng_pp_data_ready', $data, array( 'product_id' => $product_id ) );

    Feel free to look at the plugin’s code and see for yourself.

    Thread Starter johnelki

    (@johnelki)

    Excellent. Thanks very much indeed Alexander for your helpful support -it all works beautifully now.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Pre-fill non-logged in user name and email?’ is closed to new replies.