Skip to content

Commit

Permalink
fix: hide My Account links if not relevant (#3394)
Browse files Browse the repository at this point in the history
* fix: hide My Account links if not relevant

* chore: move Account Details and Subscriptions to top of menu
  • Loading branch information
dkoo authored Sep 13, 2024
1 parent 1890efe commit 0d039d8
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,35 @@ public static function my_account_menu_items( $items ) {
if ( empty( array_filter( $billing_address ) ) && empty( array_filter( $billing_address ) ) ) {
$default_disabled_items[] = 'edit-address';
}

// Hide Orders and Payment Methods if the reader has no orders.
if ( ! $customer->get_is_paying_customer() ) {
$default_disabled_items[] = 'orders';
$default_disabled_items[] = 'payment-methods';
}
}
if ( function_exists( 'wc_get_customer_available_downloads' ) ) {
$customer_id = \get_current_user_id();
$wc_customer_downloads = \wc_get_customer_available_downloads( $customer_id );
if ( empty( $wc_customer_downloads ) ) {
$default_disabled_items[] = 'downloads';
}
}
if ( function_exists( 'wcs_user_has_subscription' ) && ! \wcs_user_has_subscription( $customer_id ) ) {
$default_disabled_items[] = 'subscriptions';
}

$disabled_wc_menu_items = \apply_filters( 'newspack_my_account_disabled_pages', $default_disabled_items );
foreach ( $disabled_wc_menu_items as $key ) {
if ( isset( $items[ $key ] ) ) {
unset( $items[ $key ] );
}
}

// Move "Account Details" and "S"ubscriptions" to the top of the menu.
if ( isset( $items['subscriptions'] ) ) {
$items = [ 'subscriptions' => $items['subscriptions'] ] + $items;
}
$items = [ 'edit-account' => $items['edit-account'] ] + $items;
}

return $items;
Expand Down

0 comments on commit 0d039d8

Please sign in to comment.