0

This is the very first time I'm trying to add a shortcode. I wanna display the user membership in my custom dashboard. So in one of the PHP that builds the Woocommerce member area (/wp-content/plugins/woocommerce-memberships/includes/frontend/class-wc-memberships-members-area.php), I found:

/**
     * Returns the user membership to display in members area.
     *
     * @since 1.7.4
     *
     * @return false|\WC_Memberships_User_Membership current user membership object
     */
    public function get_members_area_user_membership() {
        return wc_memberships_get_user_membership( get_current_user_id(), $this->get_members_area_membership_plan_id() );
    }

Using this idea, I'm trying to create my_function, add this to my_shortcode and paste the snippet on my template's function.php:

    // function that runs when shortcode is called
function my_function() { 

// Things that you want to do. 
public function get_members_area_user_membership() {
        return wc_memberships_get_user_membership( get_current_user_id(), $this->get_members_area_membership_plan_id() );
    }

// register shortcode
add_shortcode('my_shortcode', 'my_function'); 

Of course, as all good first attempts, it's not working.

Could someone help me to understand what's wrong?

ERROR: Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /home4/waksli0agozc/public_html/wp-content/themes/twentyseventeen/functions.php on line 1340

Thanks in advance.

igortp
  • 179
  • 1
  • 14

1 Answers1

0

You have a function in another function and the error is explicit, remove public before function ;)

qdequippe
  • 1,075
  • 6
  • 15
  • there is no more bug since I'm using the code bellow. But it's not returning the value. Any idea? `// function that runs when shortcode is called function my_function() { // Things that you want to do. function get_members_area_user_membership() { return wc_memberships_get_user_membership( get_current_user_id(), $this->get_members_area_membership_plan_id() ); } } // register shortcode add_shortcode('current_membership', 'my_function');` – igortp Apr 21 '20 at 08:45
  • Maybe `$this->get_members_area_membership_plan_id()` does not exist where you call it. Try to import the class or something else (sorry I don't know Wordpress) – qdequippe Apr 21 '20 at 13:07