Skip to content

Instantly share code, notes, and snippets.

@davinian
Last active June 7, 2021 17:50
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 davinian/7254d5cc8a60f21fc701394a8650b2fd to your computer and use it in GitHub Desktop.
Save davinian/7254d5cc8a60f21fc701394a8650b2fd to your computer and use it in GitHub Desktop.
/**
* Add this to your WordPress Child Theme funtions.php file
* David Churchill www.seedo.media
*/
/**
* Remove Profile bits from WooCommerce
* Removing the // from the lines below to hide the sections
* In this example Address and Downloads are hidden
*/
add_filter ( 'woocommerce_account_menu_items', 'just_remove_my_account_links' );
function just_remove_my_account_links( $menu_links ){
unset( $menu_links['edit-address'] ); // Addresses
//unset( $menu_links['dashboard'] ); // Dashboard
//unset( $menu_links['payment-methods'] ); // Payment Methods
//unset( $menu_links['orders'] ); // Orders
unset( $menu_links['downloads'] ); // Downloads
//unset( $menu_links['edit-account'] ); // Account details
//unset( $menu_links['customer-logout'] ); // Logout
return $menu_links;
}
/**
* Add a Custom Link to WooCommerce My Account
* In the example below we will add a link to the WordPress Dashboard
*/
add_filter ( 'woocommerce_account_menu_items', 'add_my_account_links' );
function add_my_account_links( $menu_links ){
// we will hook "view_my_links" later
$new = array( 'view_my_links' => 'WordPress Dashboard' );
// or in case you need 2 links
// $new = array( 'link1' => 'Link 1', 'link2' => 'Link 2' );
// array_slice() is good when you want to add an element between the other ones
$menu_links = array_slice( $menu_links, 0, 7, true )
+ $new
+ array_slice( $menu_links, 7, NULL, true );
return $menu_links;
}
add_filter( 'woocommerce_get_endpoint_url', 'add_my_account_links_endpoint', 10, 4 );
function add_my_account_links_endpoint( $url, $endpoint, $value, $permalink ){
if( $endpoint === 'view_my_links' ) {
// ok, here is the place for your custom URL, it could be external
// you may need to add full url - e.g. https://yourwebsite.tld/wp-admin
$url = site_url('/wp-admin');
}
return $url;
}
/*
* Add a WordPress Dashboard Menu Link back to My Account for Subscribers Role
* Don;t forget to update the link/url below to point to your own website
*/
add_action( 'admin_menu', 'linked_url' );
function linked_url() {
add_menu_page( 'linked_url', 'My Account', 'read', 'my_slug', '', 'dashicons-admin-home', 1 );
}
add_action( 'admin_menu' , 'linkedurl_function' );
function linkedurl_function() {
global $menu;
$menu[1][2] = "https://YOURWEBSITE.TLD/my-account/";
}
/* End */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment