0

Im trying to show the value of a product field created with AFC I can see the full product object and the value is displayed correctly. Foolowing the doc I should use

$value = get_field( "geolocation" );

or

$value = get_fields( "geolocation" );

But value is always empty I have also tried to pass the product id and the item id like

$value = get_field( "geolocation", $item->get_id() );

I have printed the full object, below is the relevant part

{ 
     "id":176,
     "key":"geolocation",
     "value":{ 
         "address":"Test address",
         "lat":"20.5271494",
         "lng":"-1.6597097999999733"
      }
 }

What im trying to print is the address, lat and lng

Tyra Pululi
  • 436
  • 1
  • 7
  • 19
  • What's the field type ? textbox ? or other types ... – Mohammad Sep 25 '19 at 13:48
  • the field type is text – Tyra Pululi Sep 25 '19 at 13:53
  • You created a field (geolocation) and that has three values (address, lat, lng) ? How it's possible ? because as you said that's a text filed ? anyway, try once with `echo $value->address;` and check output – Mohammad Sep 25 '19 at 14:51
  • actually I cant not answer that question coz I didnt make the fields. I know that I need to call those values because I printed the full object – Tyra Pululi Sep 25 '19 at 16:36

1 Answers1

0

I was calling the method wrong. First I needed to look into the products object

$geolocation = get_field('geolocation',$item->get_product_id());

Since in my case geolocation is an array I just needed to go through

$address = $geolocation['address'];
$lat = $geolocation['lat'];
$lng = $geolocation['lng'];

This question helped a lot Display product ACF value in Woocommerce admin email notifications

Tyra Pululi
  • 436
  • 1
  • 7
  • 19