Displaying information for a class

0

I want to show the values of a class but I do not know how to access it. The result of print_r($this->order); shows

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

I would like to return only: Alex e Silva.

    
asked by anonymous 04.07.2018 / 04:48

2 answers

0

I'm pretty sure the question is about , if In this case I do not master this, but I think it will solve using the WC_Order::get_data() method because the variable is protected (protected), according to the Woocommerce API documentation:

So when you get this you can do a var_dump and note what was returned, you 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 look something like:

$nome = $obj->get_shipping_first_name();
$sobrenome = $obj->get_shipping_last_name();
    
04.07.2018 / 05:35
0

Two things:

  • You can not access this object directly because it is protected
  • If it 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']);
    
04.07.2018 / 05:24