[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.
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.
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....
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?
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.
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?
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 );
}
}
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.