WC_Shortcode_My_Account::my_account_add_noticesprivate staticWC 1.0

Add notices to the my account page.

Historically a filter has existed to render a message above the my account page content while the user is logged out. See woocommerce_my_account_message.

Method of the class: WC_Shortcode_My_Account{}

Hooks from the method

Returns

null. Nothing (null).

Usage

$result = WC_Shortcode_My_Account::my_account_add_notices();

WC_Shortcode_My_Account::my_account_add_notices() code WC 11.0.0

private static function my_account_add_notices() {
	global $wp;

	if ( ! is_user_logged_in() ) {
		/**
		 * Filters the message shown on the 'my account' page when the user is not logged in.
		 *
		 * @since 2.6.0
		 */
		$message = apply_filters( 'woocommerce_my_account_message', '' );

		if ( ! empty( $message ) ) {
			wc_add_notice( $message );
		}
	}

	// After password reset, add confirmation message.
	if ( ! empty( $_GET['password-reset'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
		wc_add_notice( __( 'Your password has been reset successfully.', 'woocommerce' ) );
	}

	// After logging out without a nonce, add confirmation message.
	if ( isset( $wp->query_vars['customer-logout'] ) && is_user_logged_in() ) {
		/* translators: %s: logout url */
		wc_add_notice( sprintf( __( 'Are you sure you want to log out? <a href="%s">Confirm and log out</a>', 'woocommerce' ), wc_logout_url() ) );
	}

	// Suppress the nag during the resend cooldown so it doesn't contradict the "we emailed you" confirmation.
	// Driven off the same timestamp WC_Form_Handler::resend_set_password() writes, so the notice reappears
	// once the cooldown lapses and the link can be requested again.
	$last_resend_at  = (int) get_user_meta( get_current_user_id(), WC_Form_Handler::SET_PASSWORD_RESEND_META, true );
	$within_cooldown = $last_resend_at > 0 && ( time() - $last_resend_at ) < WC_Form_Handler::SET_PASSWORD_RESEND_RATE_LIMIT_SECONDS;

	if ( ! $within_cooldown && get_user_option( 'default_password_nag' ) && ( wc_is_current_account_menu_item( 'dashboard' ) || wc_is_current_account_menu_item( 'edit-account' ) ) ) {
		$resend_url = wp_nonce_url( add_query_arg( 'wc-resend-set-password', '1', wc_get_page_permalink( 'myaccount' ) ), 'wc-resend-set-password' );
		wc_add_notice(
			sprintf(
				/* translators: %1$s and %2$s are opening and closing anchor tags for the resend-link button. */
				__( '%1$sResend%2$s', 'woocommerce' ),
				'<a href="' . esc_url( $resend_url ) . '" class="button wc-forward">',
				'</a>'
			) . ' ' . __( 'Your account is using a temporary password. We emailed you a link to change your password.', 'woocommerce' ),
			'notice'
		);
	}
}