From c0ab1d51834871b047b2d96f77743683634a2578 Mon Sep 17 00:00:00 2001 From: tellyworth Date: Sat, 19 Oct 2024 05:36:03 +1100 Subject: [PATCH] CampTix: Improve the logged-out ticket registration flow (#1399) * Restore the full form UI for logged-out users on the ticket purchase screen * Pass the WordCamp name in query string to use on the login form * Bypass the login check when applying a coupon * Pass through the ticket parameters via the login redirect link Logged-out users will be able to apply coupon & select tickets, and once they click Register, will be redirected to log in or register for wordpress.org. Once logged in, they'll redirect back to the checkout flow, with the coupon applied and tickets selected. Fixes #1397 --------- Co-authored-by: Kelly Dwan --- .../plugins/camptix/addons/require-login.php | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/public_html/wp-content/plugins/camptix/addons/require-login.php b/public_html/wp-content/plugins/camptix/addons/require-login.php index e4de519b8..c499cd706 100644 --- a/public_html/wp-content/plugins/camptix/addons/require-login.php +++ b/public_html/wp-content/plugins/camptix/addons/require-login.php @@ -13,10 +13,7 @@ class CampTix_Require_Login extends CampTix_Addon { * Register hook callbacks */ public function __construct() { - // Registration Information front-end screen - add_filter( 'camptix_register_button_classes', array( $this, 'hide_register_form_elements' ) ); - add_filter( 'camptix_coupon_link_classes', array( $this, 'hide_register_form_elements' ) ); - add_filter( 'camptix_quantity_row_classes', array( $this, 'hide_register_form_elements' ) ); + // Registration Information front-end screen. add_action( 'camptix_notices', array( $this, 'ticket_form_message' ), 8 ); add_filter( 'camptix_ask_questions', array( $this, 'hide_additional_attendee_questions_during_checkout' ), 10, 5 ); add_filter( 'camptix_form_register_complete_attendee_object', array( $this, 'add_username_to_attendee_object' ), 10, 3 ); @@ -59,16 +56,37 @@ public function __construct() { public function block_unauthenticated_actions() { /** @var $camptix CampTix_Plugin */ global $camptix; + // Continue normal request, this is not a tickets page. + if ( ! isset( $_REQUEST['tix_action'] ) ) { + return; + } + // Bypass for payment webhook notifications. - if ( isset( $_REQUEST['tix_action'] ) && isset( $_REQUEST['tix_payment_token'] ) && $_REQUEST['tix_action'] == 'payment_notify' ) { + if ( 'payment_notify' === $_REQUEST['tix_action'] && isset( $_REQUEST['tix_payment_token'] ) ) { + return; + } + + // Bypass for coupon validation- the `tix_coupon_submit` value is set when "Apply Coupon" button is clicked. + if ( 'attendee_info' === $_REQUEST['tix_action'] && isset( $_REQUEST['tix_coupon'], $_REQUEST['tix_coupon_submit'] ) ) { return; } - if ( ! is_user_logged_in() && isset( $_REQUEST['tix_action'] ) ) { - wp_safe_redirect( wp_login_url( add_query_arg( $_REQUEST, $camptix->get_tickets_url() ) ) ); + if ( ! is_user_logged_in() ) { + $args = array(); + // If this was a registration, pass through the selected tickets and coupon. + if ( 'attendee_info' === $_REQUEST['tix_action'] && isset( $_REQUEST['tix_tickets_selected'] ) ) { + $args['tix_action'] = $_REQUEST['tix_action']; + $args['tix_tickets_selected'] = $_REQUEST['tix_tickets_selected']; + if ( isset( $_REQUEST['tix_coupon'] ) ) { + $args['tix_coupon'] = $_REQUEST['tix_coupon']; + } + } + + $tickets_url = add_query_arg( $args, $camptix->get_tickets_url() ); + + wp_safe_redirect( add_query_arg( 'wcname', get_bloginfo( 'name' ), wp_login_url( $tickets_url ) ) ); exit(); } - } /**