E
E
ebbk2021-07-03 20:51:36
PHP
ebbk, 2021-07-03 20:51:36

How to get data from this array?

The woocommerce plugin is trying to get the name of the product but it does not work, I tried in such ways.
Please tell me how can I get it?

echo $data['data:protected']['name'];
echo $data->'data:protected'->name;
echo $data->data:protected->name;


WC_Product_Simple Object
(
    [object_type:protected] => product
    [post_type:protected] => product
    [cache_group:protected] => products
    [data:protected] => Array
        (
            [name] => Panton tunior chair //Нужно получить это
            [slug] => panton-tunior-chair
            [date_created] => WC_DateTime Object
                (
                    [utc_offset:protected] => 10800
                    [date] => 2017-06-14 08:24:57.000000
                    [timezone_type] => 1
                    [timezone] => +00:00
                )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Gorbunov, 2021-07-04
@ebbk

There are corresponding methods for getting data from the given object's data array

$product_type  = $data->get_type(); 
$product_id    = $data->get_id();
$product_name  = $data->get_name();
$product_sku   = $data->get_sku(); 
$product_price = $data->get_price();

M
My joy, 2021-07-03
@t-alexashka

echo $data->data->name;
and so?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question