I am creating a custom php code to assign orders to employees.
I have created a custom field in orders with name employee-username to store the user id of the
employee.
I also created a form to get the current login user:
Hello. Thank you for contacting the Toolset support.
I would like to know, you have a Edit post form to update the existing order value - correct?
If yes, it seems there is some issue with the code you shared but I'll be able to tell better when I can able to review your existing setup and for that I will require admin and FTP access detaials.
Can you please share on what page/post you added the Toolset form using the function cred_form()?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
First of all - After checking to debug the information you shared with us, I found that you are using outdated Toolset plugins. We always recommend running your site with the latest stable release plugin version.
*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest officially released version. You can download the latest plugin release from your accounts page:
=> https://toolset.com/account/downloads/
Once ALL Toolset plugins updated to latest release,
I checked the functions.php file and I can see that now you adjust the code there as given under where you changed the update_post_meta() to add_post_meta():
add_action('cred_save_data' , 'assignEmployee_action',10,2);
function assignEmployee_action($post_id, $form_data){
if($form_data[id]==185){
console.log("This is msg from form 18");
if(isset($_POST['emplyee-username'])){
console.log($_POST['emplyee-username']);
add_post_meta($post_id,'wpcf-emplyee-username',$_POST['emplyee-username'],true);
//update_post_meta( $order_id, 'wpcf-exeutor-username',$_POST['exeutor-username'] );
}
}
}
My issue is not yet solved, I moved my custom code to where you suggested.
Whenever I click :Get this order" in ( hidden link ) it creates new empty orders, it will not update the custom value field.
I checked and I can see that you are using the following form within the neworders custom shortcocde you added:
- hidden link
The above form is set to "Add new content " that is why its creating the new entry. I changed the "Form type" to "Edit existing content" and when I click on Get button I can see now that the username is updated.
In addition to that, I'm not sure why you created custom shortcode to display the orders as you can also query the orders by creating the view but there must be some reason behind that you created custom shrotcode.