How to view class information

Asked

Viewed 39 times

0

I want to show the values of a class but I don’t know how to access it. The result of print_r($this->order); showcase

WC_Order Object ( 
    [status_transition:protected] =>
    [data:protected] => 
        Array ( 
            [shipping] => Array ( [first_name] => Alex [last_name] => Silva ) 
        )

I would like to return only: Alex and Silva.

  • Hello Thiago, did the answer https://answall.com/a/311782/3635 solve your problem? Could you provide feedback?

2 answers

0

Two things:

  • You cannot access this object directly because it is protected
  • If you were public you could use the example below to get an idea

class Foo {
    public $data = ['shipping' => ['first_name' => 'Renato', 'last_name' => 'Tavares'] ];
}
$ob = new Foo;
var_dump($ob->data['shipping']['first_name']);

0

I’m pretty sure the question is about , if that’s the case, I can’t master this, but I think you’ll solve it using the WC_Order::get_data(), because the variable is protected (protected), according to the Woocommerce API documentation:

Then having caught it you can make one var_dump and observe what has been returned, will probably have the values.

However looking at the API documentation I noticed both methods:

Both methods apparently serve to get the data you want, so it would be something like:

$nome = $obj->get_shipping_first_name();
$sobrenome = $obj->get_shipping_last_name();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.