Skip Navigation

[Resuelto] Automatically create a custom post during User registration

This support ticket is created hace 6 años, 3 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Este tema contiene 37 respuestas, tiene 2 mensajes.

Última actualización por Shane hace 5 años, 10 meses.

Asistido por: Shane.

Autor
Mensajes
#1083972

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi sasan,

I'm having a look at this again for you.

#1083984

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Sasan,

I made some changes that should work but it seems something is preventing me from getting the user ID after its created using the form.

Could you temporarily disable all the non-toolset plugins and try again letting me know what the result is.

Thanks,
Shane

#1084072

Shane,

I disabled all plugins but no positive effect. The new post author (after your changes) is "toolset toolset" not sure why it says that. I did a var_dump of $data and found user id is always 20 no matter how many times I submit the form. I checked the docs (https://toolset.com/documentation/programmer-reference/cred-commerce-api/#cred_commerce_after_order_completed) it says "ID of the user that placed the order" so I guess its not the id of the user thats being created.

#1084419

Shane,

I was just going through the CRED Commerce plugin code, I saw that a temp user is created when order is placed. When the order is marked completed the temp user is registered as a normal wp user and the temp user is deleted. I am unable to figure out how can I get the id of the newly created user after marking the order completed. I couldnt find it being saved anywhere.

We were suppose to launch this site on 18th and open up the registrations, but unfortunately got this issue at last movement....

Regards,
Sasank

#1084652

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Sasan,

It seems that this is a limitation on our part.

Why not allow the users to manually create the company after they have registered for their user accounts instead of doing it automatically.

For instance you can redirect them to the form after they created their account, there they can fill in the company information.

Please let me know what you think of this.

Thanks,
Shane

#1084713

I had thought of that before but there is a problem, The member can pay online or pay by bank transfer or cheque. In last 2 options we will have to manually verify and approve their account. And want to allow them to add only 1 company to the listing so if the page is created while account creation itself that prob will be solved by giving them edit form and let them edit only their post not add any new one.

Is there no way to get the newly created user id? may be save it in a custom field of order while converting from temp user to wp user?

Regards,
Sasank

#1084767

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Sasan,

If the code itself is generating a temporary user ID and the actual user isn't created until after the payment has gone through then there isn't much we can do about it.

What you can try doing is to use a default custom field and store the value of the post_id in it and check the user on the backend to see if it is matching.

Based on the hook that we are using then the sequence should be that once the order is completed then the hook fires which would get the data.

Thanks,
Shane

#1084846

Shane,

Can you please take this up to developers team as requested feature? getting new user id would be really helpful.

Thanks,
Sasank

#1085833

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Sasan,

I will escalate this to our team but before I do, would you mind if I created a duplicator package from your website so they can use as basis for there test?

Thanks,
Shane

#1085847

Ya sure go ahead Shane

Regards,
Sasank

#1087524

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Sasan,

I tried logging in again to create this but it's asking me for an Authentication code.

Thanks,
Shane

#1087571

Hi Shane,

Sorry about that, was working on making the site secure. Turned off Two-Factor Authentication for now. Please try again.

Regards,
Sasank

#1087655

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Thanks,

I've escalated this for you.

#1088476

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Sasan,

Could you please try this solution here.

add_action( 'cred_commerce_after_order_completed', 'create_company_post', 10, 1 );
 
function create_company_post( $data ) {
 
    $cred_form_id = $data['extra_data'][0]['cred_form_id'];
    
    if ($cred_form_id== 765) {
	
	$cred_post_id = $data['extra_data'][0]['cred_post_id'];
    
    //database prefix of usermeta value that Forms saves againts the new user is draft_
    $prefix = 'draft_';
    //remove draft_ from the new user meta value (cred_post_id)
	$str = $data['extra_data'][0]['cred_post_id'];
	if (substr($str, 0, strlen($prefix)) == $prefix) {
		$str = substr($str, strlen($prefix));
	} 
    
    $my_post = array(
    	'post_title'    => $str,
        'post_status'   => 'draft',
        'post_author' => $str,
        'post_type' => 'company'
    );
           
      // Insert the post into the database
      wp_insert_post( $my_post );
    }
}

This should now work.

Thanks,
Shane

#1088503

Shane,

I tried it but didnt work. First, I want the title to be from company field not the user id. Second, The newly created user id was 46 but the draft id was 41 so those dont match! So, no author was assigned as before.

Regards,