Enhancement: Show account created notice on order confirmation page (#48673)

* Add notice on confirmation page for new accounts

* Reset should remove nag

* Changelog
This commit is contained in:
Mike Jolley 2024-07-01 12:41:29 +01:00 committed by GitHub
parent 6e36d92a59
commit 4ff97e4915
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 6 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Added notice to the order confirmation page for new accounts instructing them to change the default password.

View File

@ -376,6 +376,7 @@ class WC_Shortcode_My_Account {
do_action( 'password_reset', $user, $new_pass );
wp_set_password( $new_pass, $user->ID );
update_user_meta( $user->ID, 'default_password_nag', false );
self::set_reset_password_cookie();
if ( ! apply_filters( 'woocommerce_disable_password_change_notification', false ) ) {

View File

@ -40,13 +40,17 @@ class Status extends AbstractOrderConfirmationBlock {
return '';
}
$additional_content = $this->render_confirmation_notice( $order );
$additional_content = $this->render_account_notice( $order ) . $this->render_confirmation_notice( $order );
return $additional_content ? $block . sprintf(
'<div class="wc-block-order-confirmation-status-description %1$s">%2$s</div>',
esc_attr( trim( $classname ) ),
$additional_content
) : $block;
if ( $additional_content ) {
return sprintf(
'<div class="wc-block-order-confirmation-status-description %1$s">%2$s</div>',
esc_attr( trim( $classname ) ),
$additional_content
) . $block;
}
return $block;
}
/**
@ -142,6 +146,32 @@ class Status extends AbstractOrderConfirmationBlock {
return '<p>' . esc_html__( 'Please check your email for the order confirmation.', 'woocommerce' ) . '</p>';
}
/**
* If the user associated with the order needs to set a password (new account) show a notice.
*
* @param \WC_Order|null $order Order object.
* @return string
*/
protected function render_account_notice( $order = null ) {
if ( $order && $order->get_customer_id() && 'store-api' === $order->get_created_via() ) {
$nag = get_user_option( 'default_password_nag', $order->get_customer_id() );
if ( $nag ) {
return wc_print_notice(
sprintf(
// translators: %s: site name.
__( 'Your account with %s has been successfully created. We emailed you a link to set your account password.', 'woocommerce' ),
esc_html( wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ) )
),
'notice',
array(),
true
);
}
}
return '';
}
/**
* If the order is invalid or there is no permission to view the details, tell the user to check email or log-in.
*