0

I'm trying to get a team name that is associated with a user. I've gotten as far as getting the var_dump of the correct team. But the value has :private

Is there a way for me to still echo that value?

        $user_id = $post->post_author ;
        $teamnames   = wc_memberships_for_teams_get_teams( $user_id );
        foreach( $teamnames as $teamname ) {
                echo $teamname->post->post_title;
        }

Here is part of the var_dump( $teamname)

array(1) {
  [0]=>
  object(SkyVerge\WooCommerce\Memberships\Teams\Team)#27586 (19) {
    ["id":"SkyVerge\WooCommerce\Memberships\Teams\Team":private]=>
    int(65458)
    ["name":"SkyVerge\WooCommerce\Memberships\Teams\Team":private]=>
    string(17) "Clarkston Primary"
    ["date":"SkyVerge\WooCommerce\Memberships\Teams\Team":private]=>
    string(19) "2019-11-19 10:17:00"
    ["date_gmt":"SkyVerge\WooCommerce\Memberships\Teams\Team":private]=>
    string(19) "2019-11-19 10:17:00"
    ["owner_id":"SkyVerge\WooCommerce\Memberships\Teams\Team":private]=>
    int(4760)
    ["plan_id":"SkyVerge\WooCommerce\Memberships\Teams\Team":private]=>
    int(11576)
    ["registration_key":"SkyVerge\WooCommerce\Memberships\Teams\Team":private]=>
    string(32) "119a2d7697a925a1a65d88ec46b2e951"
    ["plan":"SkyVerge\WooCommerce\Memberships\Teams\Team":private]=>
    NULL
    ["post":"SkyVerge\WooCommerce\Memberships\Teams\Team":private]=>
    object(WP_Post)#27585 (24) {
      ["ID"]=>
      int(65458)
      ["post_author"]=>
      string(4) "4760"
      ["post_date"]=>
      string(19) "2019-11-19 10:17:00"
      ["post_date_gmt"]=>
      string(19) "2019-11-19 10:17:00"
      ["post_content"]=>
      string(0) ""
      ["post_title"]=>
      string(17) "Clarkston Primary"
Looq
  • 13
  • 3
  • Set a variable outside the loop as an empty string. `$teamNameVar = '' ` set that value into this variable then echo it outside the loop. – Abu Nooh Dec 14 '21 at 17:24
  • If it is private, then not without reflection. Read the documentation, there will be information on accessible functions. Failing that, read class and see what you can access (PHP-PSR4 Loaded)! `SkyVerge\WooCommerce\Memberships\Teams\Team.php` – Jaquarh Dec 14 '21 at 17:26
  • @AbuNooh I just tried that and it din't work: $teamNameVar = ' ' ; ...... foreach( $teamnames as $teamname ) { $teamNameVar = $teamname->post->post_author; } echo $teamNameVar; – Looq Dec 14 '21 at 17:32
  • @Jaquarh I've read the documentation, but not much help. How would I read the class? – Looq Dec 14 '21 at 19:23
  • how about $teamname->get_name(); ? – Snuffy Dec 15 '21 at 10:56

1 Answers1

1

Martin Mirchev answer solved what I was trying to do. I changed echo $teamname->post->post_title; to echo $teamname->get_name();

I was also able to get the id by $teamname->get_id()

Looq
  • 13
  • 3