diff --git a/includes/class-modal-checkout.php b/includes/class-modal-checkout.php index e35403838..d1a0970d3 100644 --- a/includes/class-modal-checkout.php +++ b/includes/class-modal-checkout.php @@ -124,7 +124,7 @@ public static function woocommerce_checkout_create_order_line_item( $item, $cart * Change the post-transaction return URL. * This is specifically for non-redirect-based flows, such as Apple Pay. * - * @param array $result The return payload for a successfull transaction. + * @param array $result The return payload for a successful transaction. */ public static function woocommerce_payment_successful_result( $result ) { $order_id = $result['order_id']; @@ -134,24 +134,21 @@ public static function woocommerce_payment_successful_result( $result ) { return $result; } - $originating_from_modal = ! empty( $order->get_meta( '_newspack_modal_checkout_url' ) ); - if ( $originating_from_modal ) { - $modal_checkout_url_query = \wp_parse_url( $modal_checkout_url, PHP_URL_QUERY ); - \wp_parse_str( $modal_checkout_url_query, $modal_checkout_url_query_params ); - $passed_params_names = [ 'modal_checkout', 'after_success_behavior', 'after_success_url', 'after_success_button_label' ]; - // Pick passed params from the query params. - $passed_params = array_intersect_key( $modal_checkout_url_query_params, array_flip( $passed_params_names ) ); - - $result['redirect'] = \add_query_arg( - array_merge( - $passed_params, - [ - 'order_id' => $order_id, - ] - ), - $result['redirect'] - ); - } + $modal_checkout_url_query = \wp_parse_url( $modal_checkout_url, PHP_URL_QUERY ); + \wp_parse_str( $modal_checkout_url_query, $modal_checkout_url_query_params ); + $passed_params_names = [ 'modal_checkout', 'after_success_behavior', 'after_success_url', 'after_success_button_label' ]; + // Pick passed params from the query params. + $passed_params = array_intersect_key( $modal_checkout_url_query_params, array_flip( $passed_params_names ) ); + + $result['redirect'] = \add_query_arg( + array_merge( + $passed_params, + [ + 'order_id' => $order_id, + ] + ), + $result['redirect'] + ); return $result; } @@ -1077,6 +1074,10 @@ public static function hide_expiry_message_shop_link( $message ) { * Is this request using the modal checkout? */ public static function is_modal_checkout() { + // Until we use the modal checkout flow from My Account, we don't want to show the modal checkout thank you template for checkouts originating from My Account. + if ( method_exists( 'Newspack\WooCommerce_My_Account', 'is_from_my_account' ) && \Newspack\WooCommerce_My_Account::is_from_my_account() ) { + return false; + } $is_modal_checkout = isset( $_REQUEST['modal_checkout'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! $is_modal_checkout && isset( $_REQUEST['post_data'] ) && is_string( $_REQUEST['post_data'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended diff --git a/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer.php b/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer.php index b5af4656f..00d99dee3 100644 --- a/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer.php +++ b/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer.php @@ -14,12 +14,6 @@ * Server-side rendering of the `newspack-blocks/donate` block. */ class Newspack_Blocks_Donate_Renderer { - /** - * Constructor. - */ - public function __construct() { - add_filter( 'woocommerce_checkout_fields', [ __CLASS__, 'woocommerce_checkout_fields' ] ); - } /** * Get the keys of the billing fields to render for logged out users. @@ -40,34 +34,6 @@ public static function get_billing_fields_keys() { return apply_filters( 'newspack_blocks_donate_billing_fields_keys', $fields ); } - /** - * Modify fields for modal checkout. - * - * @param array $fields Checkout fields. - * - * @return array - */ - public static function woocommerce_checkout_fields( $fields ) { - if ( ! class_exists( 'Newspack\Donations' ) || ! method_exists( 'Newspack\Donations', 'is_donation_cart' ) ) { - return $fields; - } - if ( ! \Newspack\Donations::is_donation_cart() ) { - return $fields; - } - $billing_fields = self::get_billing_fields_keys(); - if ( empty( $billing_fields ) ) { - return $fields; - } - $billing_keys = array_keys( $fields['billing'] ); - foreach ( $billing_keys as $key ) { - if ( in_array( $key, $billing_fields, true ) ) { - continue; - } - unset( $fields['billing'][ $key ] ); - } - return $fields; - } - /** * Enqueue frontend scripts and styles. *