Accessing nested php object data

91
June 15, 2018, at 12:50 PM

I'm trying to get the product attributes. I can dig into the objects like this but I get stuck here: How would I get the value 1500?

Thanks

$bundle = new WC_Product_Bundle($post->ID);
$products = $bundle->get_bundled_items();
foreach ($products as $product) {
var_dump($product->{'product'}->{'attributes'});
array(1) {
  ["energy"]=>
  object(WC_Product_Attribute)#1402 (1) {
    ["data":protected]=>
    array(6) {
      ["id"]=>
      int(0)
      ["name"]=>
      string(6) "energy"
      ["options"]=>
      array(1) {
        [0]=>
        string(4) "1500"
      }
      ["position"]=>
      int(0)
      ["visible"]=>
      bool(true)
      ["variation"]=>
      bool(false)
    }
  }
}
Answer 1

you can try getting the "1500" figure by:

$product->['product']->['attributes']['energy']['data']['options'][0]
READ ALSO
URL redirect rules adding firstvar=&secondvar=

URL redirect rules adding firstvar=&secondvar=

I have a problem with my website's htaccess file and rewrite rule

59
Pass affiliate ID as parameter on URL

Pass affiliate ID as parameter on URL

I'm looking for help trying to track the affiliate ID associated with an application submitted on my wordpress site

97
CVX solver will not run in MATLAB when called from php

CVX solver will not run in MATLAB when called from php

I have the following PHP script that calls a MATLAB script

80
CSV not importing to mySQLi

CSV not importing to mySQLi

I'm trying to import an CSV into mySQL, I'm very new to this, but to my knowledge I've followed exactly what another post on stackoverflow has said and it's still not working

108