Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi sasan,
I'm having a look at this again for you.
Shane
Supporter
Languages:
English (English )
Timezone:
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
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.
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
Shane
Supporter
Languages:
English (English )
Timezone:
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
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
Shane
Supporter
Languages:
English (English )
Timezone:
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
Shane,
Can you please take this up to developers team as requested feature? getting new user id would be really helpful.
Thanks,
Sasank
Shane
Supporter
Languages:
English (English )
Timezone:
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
Shane
Supporter
Languages:
English (English )
Timezone:
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
Hi Shane,
Sorry about that, was working on making the site secure. Turned off Two-Factor Authentication for now. Please try again.
Regards,
Sasank
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Thanks,
I've escalated this for you.
Shane
Supporter
Languages:
English (English )
Timezone:
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
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,