I'm strugeling with this ptoblem for a while. Need to pass data from JS to PHP on wordpress site. The error: enter image description here

function activatePlacesSearch(){
    var input = document.getElementById('shipping_user_location');
    var autocomplete = new google.maps.places.Autocomplete(input);
    var place;
    google.maps.event.addListener(autocomplete, 'place_changed', function(){
        place = autocomplete.getPlace();
        console.log("Latitude: "+place.geometry.location.lat());
        console.log("Longitude: "+place.geometry.location.lng());
          success: function(res){
          error: function(error){

Finally the code in responsible for autofill the address, and it works. But just simply can't send the data. On the other end i have the this code. But the issue probably on the JS lv:

function add_lat_lng_to_customer_meta($fields){
$place = json_decode($_POST['exampleJS']);
echo $place;die;
return $fields;
add_filter( 'woocommerce_customer_save_address', 'add_lat_lng_to_customer_meta' );

If any additional data is need just write me.

  • If $ is undefined then jquery didn’t load yet. Try wrapping your code with an onLoad handler – Luckyfella Sep 11 at 23:49
  • Hello @Luckyfella thanks for help. OK so before the $.ajax block I added the window.onload = () =>, The error is no longer there but the code from inside the "window.onload" block is not used. – Szelek Sep 12 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.