Skip to content

Commit 8bea997

Browse files
wputasicbor0claude
authored
CampTix: store an unknown attendee on the buyer's row as unknown (#2149)
* CampTix: store an unknown attendee on the buyer's row as unknown Follow-up to #2117. On a direct link to the ticket form, the "I don't know who will use this ticket yet" checkbox also shows on the buyer's own row. Ticking it there stored a half-unknown ticket: the stub name (only filled in when the name was empty), the buyer's real pre-filled email, and the buyer's username. Neither check on the public list catches that, so the ticket was listed as "Unknown Attendee". - add_unknown_attendee_info_stubs() always uses the stub name and the placeholder email when the box is ticked. The form only hides the fields, so it still submits whatever was pre-filled. - Row 1 gets the [[ unconfirmed ]] username when the box is ticked, so the ticket can be claimed like any other unknown ticket. The buyer's username is kept in tix_buyer_username, and get_abandoned_draft_attendee_ids() checks it too, so the buyer isn't held up by their own abandoned drafts. - A new camptix_checkout_receipt_email filter lets Require Login send the receipt to the logged-in buyer when it would go to the placeholder. See #2114 * CampTix: send the claim link on a one-ticket order for an unknown attendee Multiple purchases send each unknown attendee's ticket e-mail to the buyer, with the claim link to forward. A one-ticket order only got the receipt, which links to the buyer's own order page, so the buyer had no claim link to pass on. Adds a camptix_email_single_purchase_attendee_ticket filter after the single-purchase receipt, and Require Login uses it to send the existing unknown-attendee e-mail when the order's only ticket is unknown. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Boro Sitnikovski <buritomath@gmail.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 7e4924f commit 8bea997

3 files changed

Lines changed: 468 additions & 17 deletions

File tree

‎public_html/wp-content/plugins/camptix/addons/require-login.php‎

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public function __construct() {
2323
add_filter( 'camptix_get_attendee_email', array( $this, 'redirect_unknown_attendee_emails_to_buyer' ), 10, 2 );
2424
add_action( 'camptix_attendee_form_before_input', array( $this, 'inject_unknown_attendee_checkbox' ), 10, 3 );
2525
add_filter( 'camptix_checkout_attendee_info', array( $this, 'add_unknown_attendee_info_stubs' ) );
26+
add_filter( 'camptix_checkout_receipt_email', array( $this, 'send_receipt_to_buyer_instead_of_unknown_attendee' ) );
27+
add_filter( 'camptix_email_single_purchase_attendee_ticket', array( $this, 'send_claim_link_for_single_unknown_attendee' ), 10, 2 );
2628
add_filter( 'camptix_edit_info_cell_content', array( $this, 'show_buyer_attendee_status_instead_of_edit_link' ), 10, 2 );
2729
add_filter( 'camptix_attendee_info_default_value', array( $this, 'prepopulate_known_fields' ), 10, 5 );
2830

@@ -334,7 +336,9 @@ public function hide_additional_attendee_questions_during_checkout( $ask_questio
334336
* Add the value of the username to the Attendee object used during checkout
335337
*
336338
* The current logged in user's username will be assigned to the first ticket and the other tickets will have
337-
* an empty field because it will be filled in later when each individual confirms their registration.
339+
* an empty field because it will be filled in later when each individual confirms their registration. The first
340+
* ticket is left unconfirmed too when the buyer doesn't know who will use it, and the buyer's username is kept
341+
* separately, so CampTix still knows whose order it is.
338342
*
339343
* @param stdClass $attendee
340344
* @param array $attendee_info
@@ -344,8 +348,14 @@ public function hide_additional_attendee_questions_during_checkout( $ask_questio
344348
*/
345349
public function add_username_to_attendee_object( $attendee, $attendee_info, $attendee_order ) {
346350
if ( 1 === $attendee_order ) {
347-
$current_user = wp_get_current_user();
348-
$attendee->username = $current_user->user_login;
351+
$current_user = wp_get_current_user();
352+
353+
if ( isset( $attendee_info['unknown_attendee'] ) ) {
354+
$attendee->username = self::UNCONFIRMED_USERNAME;
355+
$attendee->buyer_username = $current_user->user_login;
356+
} else {
357+
$attendee->username = $current_user->user_login;
358+
}
349359
} else {
350360
$attendee->username = self::UNCONFIRMED_USERNAME;
351361
}
@@ -361,6 +371,10 @@ public function add_username_to_attendee_object( $attendee, $attendee_info, $att
361371
*/
362372
public function save_checkout_username_meta( $attendee_id, $attendee ) {
363373
update_post_meta( $attendee_id, 'tix_username', $attendee->username );
374+
375+
if ( ! empty( $attendee->buyer_username ) ) {
376+
update_post_meta( $attendee_id, 'tix_buyer_username', $attendee->buyer_username );
377+
}
364378
}
365379

366380
/**
@@ -595,30 +609,59 @@ protected function current_row_is_buyer( $tickets_selected, $current_ticket, $cu
595609
/**
596610
* Populate unknown attendee fields with stubbed values.
597611
*
598-
* Otherwise they would be empty and the checkout form would fail with errors.
612+
* Otherwise they would be empty and the checkout form would fail with errors. The stubs replace
613+
* whatever the fields hold, because the form only hides them: the buyer's own row is pre-filled
614+
* with the buyer's name and email, and those would otherwise be stored on the unknown ticket.
599615
*
600616
* @param array $attendee_info
601617
*
602618
* @return array
603619
*/
604620
public function add_unknown_attendee_info_stubs( $attendee_info ) {
605-
$unknown_attendee_info = $this->get_unknown_attendee_info();
606-
607621
if ( isset( $attendee_info['unknown_attendee'] ) ) {
608-
if ( empty( $attendee_info['first_name'] ) ) {
609-
$attendee_info['first_name'] = $unknown_attendee_info['first_name'];
610-
}
622+
$attendee_info = array_merge( $attendee_info, $this->get_unknown_attendee_info() );
623+
}
611624

612-
if ( empty( $attendee_info['last_name'] ) ) {
613-
$attendee_info['last_name'] = $unknown_attendee_info['last_name'];
614-
}
625+
return $attendee_info;
626+
}
615627

616-
if ( ! is_email( $attendee_info['email'] ) ) {
617-
$attendee_info['email'] = $unknown_attendee_info['email'];
618-
}
628+
/**
629+
* Send the receipt to the buyer when it would go to an unknown attendee.
630+
*
631+
* The receipt goes to the email of the attendee the buyer picked, which is their own row by default.
632+
* An unknown attendee's email is the placeholder, and e-mails for unknown attendees are redirected to
633+
* the receipt address, so otherwise the buyer would get neither the receipt nor the ticket.
634+
*
635+
* @param string|false $receipt_email
636+
*
637+
* @return string|false
638+
*/
639+
public function send_receipt_to_buyer_instead_of_unknown_attendee( $receipt_email ) {
640+
if ( self::UNKNOWN_ATTENDEE_EMAIL === $receipt_email ) {
641+
$receipt_email = wp_get_current_user()->user_email;
619642
}
620643

621-
return $attendee_info;
644+
return $receipt_email;
645+
}
646+
647+
/**
648+
* Send the claim link e-mail for a one-ticket order whose attendee is unknown.
649+
*
650+
* Multiple purchases send each unknown attendee's ticket e-mail to the buyer, with the claim link to
651+
* forward. A one-ticket order only gets the receipt, whose link is the buyer's own order page, so the
652+
* buyer would have no claim link to pass on.
653+
*
654+
* @param bool $send
655+
* @param WP_Post $attendee
656+
*
657+
* @return bool
658+
*/
659+
public function send_claim_link_for_single_unknown_attendee( $send, $attendee ) {
660+
if ( self::UNKNOWN_ATTENDEE_EMAIL === get_post_meta( $attendee->ID, 'tix_email', true ) ) {
661+
$send = true;
662+
}
663+
664+
return $send;
622665
}
623666

624667
/**

‎public_html/wp-content/plugins/camptix/camptix.php‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6385,6 +6385,14 @@ function form_checkout() {
63856385
if ( isset( $_POST['tix_receipt_email_js'] ) && is_email( $_POST['tix_receipt_email_js'] ) )
63866386
$receipt_email = wp_unslash( $_POST['tix_receipt_email_js'] );
63876387

6388+
/**
6389+
* Filter: Modify the address the receipt is sent to.
6390+
*
6391+
* @param string|false $receipt_email The email of the attendee the buyer picked, or false if none was picked.
6392+
* @param array $attendees The attendees being checked out.
6393+
*/
6394+
$receipt_email = apply_filters( 'camptix_checkout_receipt_email', $receipt_email, $attendees );
6395+
63886396
if ( ! is_email( $receipt_email ) )
63896397
$this->error_flags['no_receipt_email'] = true;
63906398

@@ -6529,7 +6537,9 @@ function get_draft_release_at( $attendee_id ) {
65296537
* Attendee ids of the buyer's own abandoned draft orders: drafts on the payment token of a
65306538
* buyer row, whose release time has passed. The buyer row is the one require-login stamps
65316539
* with the buyer's tix_username: the first attendee of the order, the rest carrying its
6532-
* unconfirmed placeholder until each confirms. Without require-login nothing is stamped
6540+
* unconfirmed placeholder until each confirms. When the buyer doesn't know who will use
6541+
* the first ticket either, it carries the placeholder too, and the buyer's username is in
6542+
* tix_buyer_username instead. Without require-login nothing is stamped
65336543
* and this is always empty, as it is when logged out. Their sessions are dead, so they can
65346544
* be left out of the buyer's own counts without any risk of two seats; the sweep times
65356545
* them out.
@@ -6559,10 +6569,15 @@ function get_abandoned_draft_attendee_ids() {
65596569
'posts_per_page' => -1,
65606570
'cache_results' => ! $this->checkout_lock_open,
65616571
'meta_query' => array(
6572+
'relation' => 'OR',
65626573
array(
65636574
'key' => 'tix_username',
65646575
'value' => $login,
65656576
),
6577+
array(
6578+
'key' => 'tix_buyer_username',
6579+
'value' => $login,
6580+
),
65666581
),
65676582
) );
65686583

@@ -7412,6 +7427,16 @@ function email_tickets( $payment_token = false, $from_status = 'draft', $to_stat
74127427

74137428
do_action( 'camptix_ticket_emailed', $receipt_attendee->ID );
74147429

7430+
/**
7431+
* Filter: Also send the attendee their own ticket e-mail, as multiple purchases do.
7432+
*
7433+
* @param bool $send Whether to send it. Default false.
7434+
* @param WP_Post $attendee The only attendee in the order.
7435+
*/
7436+
if ( apply_filters( 'camptix_email_single_purchase_attendee_ticket', false, $attendees[0] ) ) {
7437+
$this->email_attendee_ticket_multiple_template( $attendees[0] );
7438+
}
7439+
74157440
} elseif ( count( $attendees ) > 1 ) {
74167441

74177442
$email_template = apply_filters( 'camptix_email_tickets_template', 'email_template_multiple_purchase_receipt', $attendees[0] );

0 commit comments

Comments
 (0)