admin管理员组

文章数量:1323707

I have a wordpress + woocommerce site where the user can configure a product and create a custom one. The software that handle this configuration is on another server. So i need to send some data in POST and then, after the procedure on the external site is completed, retrieve the data and save the product as a woocommerce product. Actually i send the id of the user to the external site and retrieve it in post (the external site pass back the value that i've sent without changes).

This is the scenario: 1 - page1.php on the wordpress site --> form that send post data to external url. The user is already logged on woocommerce. The form is like this:

<form action="external site url.aspx" method="post" enctype="multipart/form-data">
<input type="hidden" name="CC" value="userID"> // this value is the wordpress user ID and is passed on external site
... other form fields
<button type="submit">Submit</button>
</form>

2 - The user is redirected to external site and do some stuff, after that the external site send post data and redirect on wordpress site

3 - page2.php on the wordpress site --> receive post data. The code that read the post data is like this:

if($_POST && $_POST['DO'] == 'save') {
  $userID = $_POST['CC'];
  wp_set_current_user($userID); 
  //take the other post parameters and do stuff...
}

In particular $POST['CC'] is the id of the user. The problem is that the user when is redirected on page2.php is not logged anymore on woocommerce. So i've used wp_set_current_user since i have the id of the user in post. I hope that now it's more clear.

Is it correct?

本文标签: serverCorrect user sessioncookie handling with external site connection in wordpress