Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to echo membership values from this array?

Been trying to echo these individual values from this array

echo var_dump($memberships);

The two values I’m trying to echo are the ["name"] and ["status"]

This is what I’ve tried to echo those values:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

if ( $memberships ) {
  foreach( $memberships[0] as $membership ) {
    echo $membership["plan"]["name"];
  }
}

I’ve also tried this:

echo $memberships[0]['plan']['name'];

This is part of the var_dump (stack won’t allow me to put the whole thing):

array(1) {
  [0]=>
  object(WC_Memberships_Integration_Subscriptions_User_Membership)#23837 (22) {
    ["subscription_id":protected]=>
    int(103981)
    ["subscription_id_meta":protected]=>
    string(16) "_subscription_id"
    ["has_installment_plan_meta":protected]=>
    string(21) "_has_installment_plan"
    ["free_trial_end_date_meta":protected]=>
    string(20) "_free_trial_end_date"
    ["id"]=>
    int(104104)
    ["plan_id"]=>
    int(98065)
    ["plan"]=>
    object(WC_Memberships_Integration_Subscriptions_Membership_Plan)#23902 (19) {
      ["installment_plan_meta":protected]=>
      string(30) "_subscription_installment_plan"
      ["id"]=>
      int(98065)
      ["name"]=>
      string(19) "Full Premium Member"
    

>Solution :

$memberships is an array of objects. Accessing members of an object is done via -> operator instead of curly braces:

foreach( $memberships as $membership ) {
echo $membership->plan->name;

}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading