Skip Navigation

[Resolved] Preview user created via CRED user form while the payment status is pending

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use a CRED Commerce form to create Users. While payment is pending, I would like to be able to show a preview of the User on my site, but I cannot use Views to display the User yet. How can I show a preview of the pending User account?

Solution: You cannot access a pending User's account information, because that information does not exist in an accessible way in the database. Instead, you could use the CRED API to insert a temporary post using the information gathered by your CRED Commerce form. Then use that temporary post as a placeholder for your pending User.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Shreyas Khatri 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#602242
email notification.png
user-status.png

I’ve successfully created CRED user form for website membership over here:
hidden link

and also successfully integrated it with CRED Commerce (WooCommerce) for collecting payment for the membership.

Once the payment is complete, the WooCommerce order shows it as ‘processing’ which is correct.

However, the user is not generated till the order is marked as ‘complete’ in WooCommerce orders - which also what we want.

I want to preview/see CRED User created via CRED user while the payment status is still ‘processing’ so I can review the user information and accordingly mark the WooCommerce order as complete.

In the CRED User Form, I’ve email notification setup which sends username/password once the order is marked as complete. (screenshot attached).

I also tried to combination in "User status when the payment status updates” settings of ‘create user’ when ‘purchase processing’, but it still doesn’t show the user in the user section unless the order is marked complete.

#602377

In the setup you have described, the WordPress User is not actually created until the Order is completed in WooCommerce. The pending User information is stored in an options table in a way that is not very accessible. Since the User is not actually created, it's not possible to use a View to access that User information, nor is it possible to use WordPress APIs to access that User's information. No User ID is created yet, so you can't store any information in the User Meta table.

If I were trying to see information from a pending User, I would probably use custom code to create a workaround. Make a custom post type called "Temp User" or something similar, and use the CRED Commerce API to copy all the information from the User registration form into this new post when the form is submitted. Then you could create a View of all the Temp User posts so you can see their information. When the actual User is created, you can delete this temporary post.

CRED Commerce API documentation:
https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_form_action

#603397

Hi Christian,

Greetings of the new year. Thanks for wonderful suggestion. We are working on this and I will update you about the status.

#603534

That sounds fine. I will mark this ticket as pending an update from you. No need to reply right now. The ticket will remain open for 30 days.

#604263

Hi Christian,

We could achieve exactly what we wanted with your guidance.

Here's our code that we added in functions file.


  add_action('cred_commerce_form_action', 'my_commerce_form_action',10,4);
function my_commerce_form_action( $action, $form_id, $post_id, $form_data ) {
  if ($form_id == 123)
  {    
    // uncomment next line to inspect the entire post object using server logs.
    // error_log(print_r($_POST, true));
    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
     $temp_post_title = $first_name . ' ' . $last_name;
              

//    function wpmix_publish_post() {
          //  global $user_ID;
            $new_post = array(
              'post_title' => $temp_post_title,
              /*'post_title' => 'Publish your own post',*/
              'post_content' => '',
              'post_status' => 'publish',
              'post_date' => date('Y-m-d H:i:s'),
              'post_author' => XX,
              'post_type' => 'temp-user',
              'post_category' => array(0),
              'meta_input' => array(
                  /*'wpcf-mobile-number' => $_POST['wpcf-mobile-number'],*/
               
                  'wpcf-tu-are-you-an-indian-citizen-and-residing-in-india' => $_POST['radios-wpcf-are-you-an-indian-citizen-and-residing-in-india'],
                  'wpcf-tu-email' => $_POST['user_email'],
                  'wpcf-tu-date-of-birth' => $_POST['wpcf-date-of-birth'],
                  'wpcf-tu-mobile-number'=> $_POST['wpcf-mobile-number']
                )
            );
            $post_id = wp_insert_post($new_post);
    exit();
  }
}