Advertisement
fauzanjeg

Restrict some Menu Account Page for Customer Role

Dec 22nd, 2021
1,568
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. /* Remove Spesific Menu in Account Page */
  2. function remove_spesific_menu_account_page( $endpoint ) {
  3.     $user = wp_get_current_user();
  4.     if ( in_array( 'customer', $user->roles ) ) { /* For Role Customer */
  5.         unset( $endpoint['edit_account'] ); /* Remove Menu Edit Account */
  6.         unset( $endpoint['post_view_stats'] ); /* Remove Menu Post View Stats */
  7.         unset( $endpoint['change_password'] ); /* Remove Menu Change Password, because already in WooCommerce Account Page */
  8.     }
  9.     return $endpoint;
  10. }
  11. add_filter( 'jnews_account_page_endpoint', 'remove_spesific_menu_account_page' );
  12.  
  13. /* Change Account Menu Dropdown */
  14. function change_dropdown_link_account_menu( $dropdown ) {
  15.    
  16.     $user = wp_get_current_user();
  17.     if ( in_array( 'customer', $user->roles ) ) { /* For Role Customer */
  18.         if ( isset( $dropdown['account'] ) ) {
  19.             $endpoint = \JNews\AccountPage::getInstance()->get_endpoint();
  20.             $dropdown['account'] = array(
  21.                 'text' => jnews_return_translation($endpoint['account']['title'], 'jnews', $endpoint['account']['label']),
  22.                 'url'  => esc_url( home_url_multilang( $endpoint['account']['slug'] . '/' . $endpoint['jnews_paywall_sub']['slug'] ) ), /* Change URL of My Account */
  23.             );
  24.         }
  25.     }
  26.     return $dropdown;
  27. }
  28. add_filter( 'jnews_dropdown_link', 'change_dropdown_link_account_menu', 99 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement