How to Customize the Account
The Sunshine Photo Cart plugin provides a flexible account menu for your customers. You can easily add, edit, or remove items from this menu using the sunshine_account_menu_items
filter. Here's how you can do it with simple code examples.
Default Account Menu Items
By default, the account menu includes the following items:
- Dashboard
- Orders
- Galleries
- Addresses
- Account Details
- Logout
These items are generated by the sunshine_get_account_menu_items()
function. The filter sunshine_account_menu_items
allows you to modify this menu.
Adding a New Menu Item
To add a custom menu item, use the following code snippet:
add_filter( 'sunshine_account_menu_items', 'custom_add_account_menu_item' );
function custom_add_account_menu_item( $items ) {
$items['custom_page'] = array(
'url' => sunshine_get_account_endpoint_url( 'custom_page' ),
'label' => __( 'Custom Page', 'sunshine-photo-cart' ),
'order' => 60,
);
return $items;
}
Learn how to add this custom code to your WordPress website
In this example, a new menu item Custom Page is added to the menu with an order of 60.
Editing an Existing Menu Item
To change the label or URL of an existing menu item, modify the corresponding array key. For example, to change the Orders menu item:
add_filter( 'sunshine_account_menu_items', 'custom_edit_account_menu_item' );
function custom_edit_account_menu_item( $items ) {
if ( isset( $items['orders'] ) ) {
$items['orders']['label'] = __( 'My Purchases', 'sunshine-photo-cart' );
$items['orders']['url'] = sunshine_get_account_endpoint_url( 'my-purchases' );
}
return $items;
}
Learn how to add this custom code to your WordPress website
This will rename the Orders menu item to My Purchases and change its URL.
Removing a Menu Item
If you want to remove an item from the menu, simply unset it from the array:
add_filter( 'sunshine_account_menu_items', 'custom_remove_account_menu_item' );
function custom_remove_account_menu_item( $items ) {
if ( isset( $items['addresses'] ) ) {
unset( $items['addresses'] );
}
return $items;
}
Learn how to add this custom code to your WordPress website
This example will remove the Addresses item from the menu.
Reordering Menu Items
Menu items are ordered using the order
parameter. Lower numbers appear first. To change the order of existing items, adjust their order values:
add_filter( 'sunshine_account_menu_items', 'custom_reorder_account_menu_items' );
function custom_reorder_account_menu_items( $items ) {
if ( isset( $items['profile'] ) ) {
$items['profile']['order'] = 15;
}
if ( isset( $items['galleries'] ) ) {
$items['galleries']['order'] = 25;
}
return $items;
}
Learn how to add this custom code to your WordPress website
Combining Changes
You can combine adding, editing, and removing menu items within a single filter function. Just make sure to return the updated $items
array.
add_filter( 'sunshine_account_menu_items', 'custom_modify_account_menu_items' );
function custom_modify_account_menu_items( $items ) {
// Add a custom item
$items['custom_page'] = array(
'url' => sunshine_get_account_endpoint_url( 'custom_page' ),
'label' => __( 'Custom Page', 'sunshine-photo-cart' ),
'order' => 60,
);
// Edit an existing item
if ( isset( $items['orders'] ) ) {
$items['orders']['label'] = __( 'My Purchases', 'sunshine-photo-cart' );
}
// Remove an item
if ( isset( $items['addresses'] ) ) {
unset( $items['addresses'] );
}
return $items;
}
Learn how to add this custom code to your WordPress website
Still need help?
If you have not yet found your answer in the documentation articles, please contact support