Skip to content

Instantly share code, notes, and snippets.

@nfsarmento
Created March 29, 2023 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nfsarmento/bb24afaaef3c5409b04790990deff5fb to your computer and use it in GitHub Desktop.
Save nfsarmento/bb24afaaef3c5409b04790990deff5fb to your computer and use it in GitHub Desktop.
Add new WooCommerce account menu item for a specific members role
<?php
/*
*
* Add new WooCommerce account menu item for a specific members role
*
* */
add_filter ( 'woocommerce_account_menu_items', 'ns_members_link', 40 );
function ns_members_link( $menu_links ){
$product_ids = array( 38, 41, 85, 95 );
if ( current_user_can('subscriber') || current_user_can('administrator') || current_user_can('xzy-administrators') || current_user_can('members') ) {
$menu_links = array_slice( $menu_links, 0, 3, true )
+ array( 'welcome-to-your-membership-area' => 'Members area' )
+ array_slice( $menu_links, 3, NULL, true );
}
return $menu_links;
}
// register permalink endpoint
add_action( 'init', 'ns_members_link_add_endpoint' );
function ns_members_link_add_endpoint() {
add_rewrite_endpoint( 'welcome-to-your-membership-area', EP_PAGES );
}
add_filter( 'woocommerce_get_endpoint_url', function ( $url, $endpoint, $value, $permalink ) {
if ( $endpoint === 'welcome-to-your-membership-area' ) {
$url = home_url( 'welcome-to-your-membership-area' );
}
return $url;
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment