Skip to content

Commit

Permalink
Change the logic flow for the order confirmation thankyou screen
Browse files Browse the repository at this point in the history
On the heels of #38983 and #39191, this changes the flow a bit so that
the "thank you" message will always be shown when loading the "order
received" URL. However, the verification requirement still prevents
the details of the order being shown unless the customer is verified,
either by confirming the email or by logging in. If unverified, the
login/email form is shown on the thank you screen instead of the order
details.
  • Loading branch information
coreymckrill committed Jul 25, 2023
1 parent b57f988 commit c451ccf
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 46 deletions.
Expand Up @@ -297,29 +297,19 @@ private static function order_received( $order_id = 0 ) {
return;
}

$template_args = array( 'order' => $order );
$order_customer_id = $order->get_customer_id();

// For non-guest orders, require the user to be logged in before showing this page.
if ( $order_customer_id && get_current_user_id() !== $order_customer_id ) {
wc_print_notice( esc_html__( 'Please log in to your account to view this order.', 'woocommerce' ), 'notice' );
woocommerce_login_form( array( 'redirect' => $order->get_checkout_order_received_url() ) );
return;
}

// For guest orders, request they verify their email address (unless we can identify them via the active user session).
if ( self::guest_should_verify_email( $order, 'order-received' ) ) {
wc_get_template(
'checkout/form-verify-email.php',
array(
'failed_submission' => ! empty( $_POST['email'] ), // phpcs:ignore WordPress.Security.NonceVerification.Missing
'verify_url' => $order->get_checkout_order_received_url(),
)
);
return;
if ( ! $order_customer_id && self::guest_should_verify_email( $order, 'order-received' ) ) {
// For guest orders, request they verify their email address (unless we can identify them via the active user session).
$template_args['needs_verification'] = 'email';
} elseif ( $order_customer_id && get_current_user_id() !== $order_customer_id ) {
// For non-guest orders, require the user to be logged in before showing this page.
$template_args['needs_verification'] = 'login';
}

// Otherwise, display the thank you (order received) page.
wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) );
wc_get_template( 'checkout/thankyou.php', $template_args );
}

/**
Expand Down
83 changes: 55 additions & 28 deletions plugins/woocommerce/templates/checkout/thankyou.php
Expand Up @@ -12,7 +12,7 @@
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 3.7.0
* @version 8.0.0
*/

defined( 'ABSPATH' ) || exit;
Expand Down Expand Up @@ -41,43 +41,70 @@

<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', esc_html__( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>

<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
<?php if ( $needs_verification ) : ?>

<li class="woocommerce-order-overview__order order">
<?php esc_html_e( 'Order number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
</li>
<?php if ( 'login' === $needs_verification ) : ?>

<li class="woocommerce-order-overview__date date">
<?php esc_html_e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo wc_format_datetime( $order->get_date_created() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
</li>
<?php
wc_print_notice( esc_html__( 'Please log in to your account to view this order.', 'woocommerce' ), 'notice' );
woocommerce_login_form( array( 'redirect' => $order->get_checkout_order_received_url() ) );
?>

<?php elseif ( 'email' === $needs_verification ) : ?>

<?php
wc_get_template(
'checkout/form-verify-email.php',
array(
'failed_submission' => ! empty( $_POST['email'] ), // phpcs:ignore WordPress.Security.NonceVerification.Missing
'verify_url' => $order->get_checkout_order_received_url(),
)
);
?>

<?php if ( is_user_logged_in() && $order->get_user_id() === get_current_user_id() && $order->get_billing_email() ) : ?>
<li class="woocommerce-order-overview__email email">
<?php esc_html_e( 'Email:', 'woocommerce' ); ?>
<strong><?php echo $order->get_billing_email(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
</li>
<?php endif; ?>

<li class="woocommerce-order-overview__total total">
<?php esc_html_e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
</li>
<?php else : ?>

<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">

<?php if ( $order->get_payment_method_title() ) : ?>
<li class="woocommerce-order-overview__payment-method method">
<?php esc_html_e( 'Payment method:', 'woocommerce' ); ?>
<strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong>
<li class="woocommerce-order-overview__order order">
<?php esc_html_e( 'Order number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
</li>
<?php endif; ?>

</ul>
<li class="woocommerce-order-overview__date date">
<?php esc_html_e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo wc_format_datetime( $order->get_date_created() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
</li>

<?php endif; ?>
<?php if ( is_user_logged_in() && $order->get_user_id() === get_current_user_id() && $order->get_billing_email() ) : ?>
<li class="woocommerce-order-overview__email email">
<?php esc_html_e( 'Email:', 'woocommerce' ); ?>
<strong><?php echo $order->get_billing_email(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
</li>
<?php endif; ?>

<?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
<li class="woocommerce-order-overview__total total">
<?php esc_html_e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
</li>

<?php if ( $order->get_payment_method_title() ) : ?>
<li class="woocommerce-order-overview__payment-method method">
<?php esc_html_e( 'Payment method:', 'woocommerce' ); ?>
<strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong>
</li>
<?php endif; ?>

</ul>

<?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>

<?php endif; ?>

<?php endif; ?>

<?php else : ?>

Expand Down

0 comments on commit c451ccf

Please sign in to comment.