From 02820f5198ae3999b7082a00d60d71ce5fab8c4b Mon Sep 17 00:00:00 2001 From: oaratovskyi Date: Wed, 13 Sep 2023 19:39:36 +0300 Subject: [PATCH 1/2] Add changelog + initial implementation --- changelog/fix-7042-double-payments-badge | 4 ++++ includes/admin/class-wc-payments-admin.php | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 changelog/fix-7042-double-payments-badge diff --git a/changelog/fix-7042-double-payments-badge b/changelog/fix-7042-double-payments-badge new file mode 100644 index 00000000000..35b2a889b49 --- /dev/null +++ b/changelog/fix-7042-double-payments-badge @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix double indicators showing under Payments tab diff --git a/includes/admin/class-wc-payments-admin.php b/includes/admin/class-wc-payments-admin.php index c6695067a9e..6a8a971f559 100644 --- a/includes/admin/class-wc-payments-admin.php +++ b/includes/admin/class-wc-payments-admin.php @@ -954,9 +954,15 @@ public function add_menu_notification_badge() { return; } + $badge = self::MENU_NOTIFICATION_BADGE; foreach ( $menu as $index => $menu_item ) { - if ( 'wc-admin&path=/payments/connect' === $menu_item[2] ) { - $menu[ $index ][0] .= self::MENU_NOTIFICATION_BADGE; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + if ( false === strpos( $menu_item[0], $badge ) + && ( 'wc-admin&path=/payments/connect' === $menu_item[2] + || 'admin.php?page=wc-admin&path=/payments/connect' === $menu_item[2] ) + ) { + $menu[ $index ][0] .= $badge; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + + // One menu item with a badge is more than enough. break; } } From fc77d887f8a2a3f07daa065e8d0256d9f3624bc9 Mon Sep 17 00:00:00 2001 From: oaratovskyi Date: Wed, 13 Sep 2023 20:19:05 +0300 Subject: [PATCH 2/2] Add check for existing badge in incentives service --- includes/admin/class-wc-payments-admin.php | 5 +---- includes/class-wc-payments-incentives-service.php | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/admin/class-wc-payments-admin.php b/includes/admin/class-wc-payments-admin.php index 6a8a971f559..394fd38051b 100644 --- a/includes/admin/class-wc-payments-admin.php +++ b/includes/admin/class-wc-payments-admin.php @@ -956,10 +956,7 @@ public function add_menu_notification_badge() { $badge = self::MENU_NOTIFICATION_BADGE; foreach ( $menu as $index => $menu_item ) { - if ( false === strpos( $menu_item[0], $badge ) - && ( 'wc-admin&path=/payments/connect' === $menu_item[2] - || 'admin.php?page=wc-admin&path=/payments/connect' === $menu_item[2] ) - ) { + if ( false === strpos( $menu_item[0], $badge ) && ( 'wc-admin&path=/payments/connect' === $menu_item[2] ) ) { $menu[ $index ][0] .= $badge; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited // One menu item with a badge is more than enough. diff --git a/includes/class-wc-payments-incentives-service.php b/includes/class-wc-payments-incentives-service.php index 5425175a6d9..240bbcf8782 100644 --- a/includes/class-wc-payments-incentives-service.php +++ b/includes/class-wc-payments-incentives-service.php @@ -48,9 +48,12 @@ public function add_payments_menu_badge(): void { return; } + $badge = WC_Payments_Admin::MENU_NOTIFICATION_BADGE; foreach ( $menu as $index => $menu_item ) { - if ( 'wc-admin&path=/payments/connect' === $menu_item[2] ) { - $menu[ $index ][0] .= WC_Payments_Admin::MENU_NOTIFICATION_BADGE; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + if ( false === strpos( $menu_item[0], $badge ) && ( 'wc-admin&path=/payments/connect' === $menu_item[2] ) ) { + $menu[ $index ][0] .= $badge; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + + // One menu item with a badge is more than enough. break; } }