Reputation: 587
I've tried out a bunch of the answers on here and figure this should be really simple.. trying to get into a hook for a woo pdf export plugin to integrate with ACF..
If I run this -
echo $this->order
I get this -
{"id":7,"parent_id":0,"status":"processing","currency":"GBP","vers
How can I pull out just the id aka first item?
Many thanks!
SOLUTION:
As per below essentially, the code I used that works is..
$thisOrd = $this->order;
$obj = json_decode($thisOrd);
echo $obj->id;
Thanks All.
Upvotes: 0
Views: 38
Reputation: 670
convert it to array first
$arr = json_decode($this->order,true);
var_dump($arr['id'])
Upvotes: 0
Reputation: 705
You could try to decode the json string, into a stdObject
$obj = json_decode($this->order);
echo $obj->id; // 7
Upvotes: 1