N
N
Nikita2017-10-02 17:45:37
PHP
Nikita, 2017-10-02 17:45:37

How to return data from ajax request to php function?

Good evening!

I have a wordpress + woocommerce site.
I am writing a plugin for calculating the cost of delivery by api.

The system is as follows:
On the checkout page, in the "city" field, enter the name of the city, the autocomplete library is connected to the field itself, which works from the same service and pulls the city code into the hidden field.

Further, through php we send a request to the service, where one of the parameters is the city code and the shipping cost is returned to us, etc.

The problem is that the city code that ajax returns is not available in the php function.

Task:
How to get access to data received by ajax in php or at least how to save it in session in woocommerce.
( In session, in which woocommerce stores the values ​​of the filled fields of the given order )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur K., 2017-10-12
@amark

1) why not make a second ajax request and pass the data to php?
2) why not take the hidden field in the form and pass to php via sumbit? accordingly, the required field inside the script is caught in $_REQUEST

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question