Automattic\WooCommerce\Internal\Admin\Settings

PaymentsController::add_menupublicWC 1.0

Adds the Payments top-level menu item.

Method of the class: PaymentsController{}

No Hooks.

Returns

null. Nothing (null).

Usage

$PaymentsController = new PaymentsController();
$PaymentsController->add_menu();

PaymentsController::add_menu() code WC 9.9.3

public function add_menu() {
	global $menu;

	// When WooPayments account is onboarded, WooPayments will own the Payments menu item since it is the native Woo payments solution.
	if ( $this->is_woopayments_account_onboarded() ) {
		return;
	} else {
		// Otherwise, remove Payments menu item linking to the connect page to avoid Payments menu item duplication.
		remove_menu_page( 'wc-admin&path=/payments/connect' );
	}

	$menu_title = esc_html__( 'Payments', 'woocommerce' );
	$menu_icon  = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4NTIiIGhlaWdodD0iNjg0Ij48cGF0aCBmaWxsPSIjYTJhYWIyIiBkPSJNODIgODZ2NTEyaDY4NFY4NlptMCA1OThjLTQ4IDAtODQtMzgtODQtODZWODZDLTIgMzggMzQgMCA4MiAwaDY4NGM0OCAwIDg0IDM4IDg0IDg2djUxMmMwIDQ4LTM2IDg2LTg0IDg2em0zODQtNTU2djQ0aDg2djg0SDM4MnY0NGgxMjhjMjQgMCA0MiAxOCA0MiA0MnYxMjhjMCAyNC0xOCA0Mi00MiA0MmgtNDR2NDRoLTg0di00NGgtODZ2LTg0aDE3MHYtNDRIMzM4Yy0yNCAwLTQyLTE4LTQyLTQyVjIxNGMwLTI0IDE4LTQyIDQyLTQyaDQ0di00NHoiLz48L3N2Zz4=';
	// Link to the Payments settings page.
	$menu_path = 'admin.php?page=wc-settings&tab=checkout&from=' . Payments::FROM_PAYMENTS_MENU_ITEM;

	add_menu_page(
		$menu_title,
		$menu_title,
		'manage_woocommerce', // Capability required to see the menu item.
		$menu_path,
		null,
		$menu_icon,
		56, // Position after WooCommerce Product menu item.
	);

	// If there are providers with an active incentive, add a notice badge to the Payments menu item.
	if ( $this->store_has_providers_with_incentive() ) {
		$badge = ' <span class="wcpay-menu-badge awaiting-mod count-1"><span class="plugin-count">1</span></span>';
		foreach ( $menu as $index => $menu_item ) {
			// Only add the badge markup if not already present and the menu item is the Payments menu item.
			if ( 0 === strpos( $menu_item[0], $menu_title )
				&& $menu_path === $menu_item[2]
				&& false === strpos( $menu_item[0], $badge ) ) {

				$menu[ $index ][0] .= $badge; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited

				// One menu item with a badge is more than enough.
				break;
			}
		}
	}
}