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.