Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WC Memberships: Tweaks for custom member area section tutorial
* Creates the welcome section first in the member area
* @param array $sections the sections of the member area
* @return array $new_sections the updated array of sections
function my_custom_members_area_sections( $sections ) {
// create a new section array so "Welcome" can be first
$new_sections = array();
$new_sections['welcome'] = __( 'Welcome', 'my-textdomain' );
// re-add the other sections so they're still present
foreach( $sections as $key => $section ) {
$new_sections[ $key ] = $section;
return $new_sections;
add_filter( 'wc_membership_plan_members_area_sections', 'my_custom_members_area_sections' );
* Change the "View" link to the Member area from "My Memberships"
* Use the new welcome section instead of "My Content"
* @param array $default_actions the default actions for the member area
* @param \WC_Memberships_User_Membership the current user's membership
* @param obj $object the post or product object (if relevant)
* @return array $default_actions the updated array of actions
function wcm_change_members_area_view_link( $default_actions, $user_membership, $object ) {
$members_area = $user_membership->get_plan()->get_members_area_sections();
// let's make our keys = values so we don't need to know array position & can use section id below
$members_area = array_combine( $members_area, $members_area );
// link to the 'welcome' section from the "My Memberships" table instead of "My Content"
$default_actions['view']['url'] = wc_memberships_get_members_area_url( $user_membership->get_plan_id(), $members_area['welcome'] );
return $default_actions;
add_filter( 'wc_memberships_members_area_my-memberships_actions', 'wcm_change_members_area_view_link', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.