0

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.

1
  • That is a JSON String Well a part of one So look up json_decode() in the manual Commented May 26, 2017 at 23:33

3 Answers 3

1

You could try to decode the json string, into a stdObject

$obj = json_decode($this->order);
echo $obj->id; // 7
Sign up to request clarification or add additional context in comments.

Comments

0
$order = json_decode($this->order, true);
echo $order['id']

1 Comment

As he like, he can use json_decode($this->order) and the result will be an instance of stdClass or json_decode($this->order, true) and the result will be an array
0

convert it to array first

$arr = json_decode($this->order,true);
var_dump($arr['id'])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.