diff --git a/includes/class-modal-checkout.php b/includes/class-modal-checkout.php index 6ebc17d22..399c618eb 100644 --- a/includes/class-modal-checkout.php +++ b/includes/class-modal-checkout.php @@ -311,19 +311,28 @@ public static function get_checkout_template( $template ) { /** * Return URL for modal checkout "thank you" page. * - * @param string $url The URL to redirect to. + * @param string $url The URL to redirect to. + * @param WC_Order $order The order related to the transaction. * * @return string */ - public static function woocommerce_get_return_url( $url ) { + public static function woocommerce_get_return_url( $url, $order ) { if ( ! isset( $_REQUEST['modal_checkout'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return $url; } + $args = [ + 'modal_checkout' => '1', + 'email' => isset( $_REQUEST['billing_email'] ) ? rawurlencode( \sanitize_email( \wp_unslash( $_REQUEST['billing_email'] ) ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended + ]; + + // Pass order ID for modal checkout templates. + if ( $order && is_a( $order, 'WC_Order' ) ) { + $args['order_id'] = $order->get_id(); + $args['key'] = $order->get_order_key(); + } + return add_query_arg( - [ - 'modal_checkout' => '1', - 'email' => isset( $_REQUEST['billing_email'] ) ? rawurlencode( sanitize_email( wp_unslash( $_REQUEST['billing_email'] ) ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended - ], + $args, $url ); } @@ -337,13 +346,18 @@ public static function woocommerce_get_return_url( $url ) { * @return string Template file. */ public static function wc_get_template( $located, $template_name ) { + if ( ! isset( $_REQUEST['modal_checkout'] ) || ! boolval( $_REQUEST['modal_checkout'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + return $located; + } + $custom_templates = [ 'checkout/form-checkout.php' => 'src/modal-checkout/templates/checkout-form.php', 'checkout/form-billing.php' => 'src/modal-checkout/templates/billing-form.php', + 'global/form-login.php' => 'src/modal-checkout/templates/form-login.php', ]; foreach ( $custom_templates as $original_template => $custom_template ) { - if ( $template_name === $original_template && isset( $_REQUEST['modal_checkout'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + if ( $template_name === $original_template ) { $located = NEWSPACK_BLOCKS__PLUGIN_DIR . $custom_template; } } diff --git a/src/modal-checkout/checkout.scss b/src/modal-checkout/checkout.scss index c9fec24c8..0806314d7 100644 --- a/src/modal-checkout/checkout.scss +++ b/src/modal-checkout/checkout.scss @@ -180,6 +180,9 @@ transform: scale( 0 ); width: 40px; } + + .woocommerce-info { + display: none; // Hide the "Please log in to view this order" message on the thank you page. + } } .woocommerce-order-overview { color: colors.$color__text-light; diff --git a/src/modal-checkout/templates/form-login.php b/src/modal-checkout/templates/form-login.php new file mode 100644 index 000000000..b0bb8f24f --- /dev/null +++ b/src/modal-checkout/templates/form-login.php @@ -0,0 +1,91 @@ +get_order_key(), $key ); // Validate order key to prevent CSRF. + ?> + +
+ + +

+ + + +

+

+ My Account to see order details.', 'newspack-blocks' ), + \wc_get_account_endpoint_url( 'dashboard' ) + ), + 'newspack-blocks' + ); + ?> +

+ +
+