diff --git a/public_html/wp-content/plugins/camptix/camptix.php b/public_html/wp-content/plugins/camptix/camptix.php index f28a1164f..4fcb673a7 100644 --- a/public_html/wp-content/plugins/camptix/camptix.php +++ b/public_html/wp-content/plugins/camptix/camptix.php @@ -7675,6 +7675,7 @@ function payment_result( $payment_token, $result, $data = array(), $interactive if ( self::PAYMENT_STATUS_COMPLETED == $result ) { $attendee->post_status = 'publish'; wp_update_post( $attendee ); + $this->log_ticket_purchase_on_user_profile( $attendee ); } if ( self::PAYMENT_STATUS_PENDING == $result ) { @@ -7687,6 +7688,7 @@ function payment_result( $payment_token, $result, $data = array(), $interactive wp_update_post( $attendee ); update_post_meta( $attendee->ID, 'tix_refund_transaction_id', $refund_transaction_id ); update_post_meta( $attendee->ID, 'tix_refund_transaction_details', $refund_transaction_details ); + $this->update_ticket_status_on_user_profile( $attendee->ID, $attendee->post_status ); $this->log( sprintf( 'Refunded %s by user request in %s.', $transaction_id, $refund_transaction_id ), $attendee->ID, $data, 'refund' ); } @@ -8595,6 +8597,83 @@ public function is_wordcamp_closed() { public function has_tickets_available() { return $this->number_available_tickets() > 0; } + + /** + * Log the purchased ticket information on the user's profile. + * + * @param object $attendee The attendee object containing ticket information. + */ + function log_ticket_purchase_on_user_profile( $attendee ) { + $user_id = get_current_user_id(); + $purchase_history = get_user_meta( $user_id, 'wordcamp_ticket_history', true ); + + // Initialize the purchase history as an empty array if it's not already an array. + if ( ! is_array( $purchase_history ) ) { + $purchase_history = array(); + } + + // Check if the current attendee's ID is already in the purchase history. + $existing_attendee_ids = array_column( $purchase_history, 'id' ); + if ( ! in_array( $attendee->ID, $existing_attendee_ids ) ) { + // Gather ticket details to log the purchase. + $ticket_id = intval( get_post_meta( $attendee->ID, 'tix_ticket_id', true ) ); + $ticket = get_post( $ticket_id ); + $ticket_type = $ticket->post_title; + $ticket_price = $this->append_currency( (float) get_post_meta( $attendee->ID, 'tix_ticket_price', true ), false ); + $purchase_date = $attendee->post_date; + $edit_token = get_post_meta( $attendee->ID, 'tix_edit_token', true ); + $edit_link = $this->get_edit_attendee_link( $attendee->ID, $edit_token ); + $access_token = get_post_meta( $attendee->ID, 'tix_access_token', true ); + $access_link = $this->get_access_tickets_link( $access_token ); + $ticket_status = $attendee->post_status; + + // Create a new purchase entry. + $new_purchase = array( + 'id' => $attendee->ID, + 'wordcamp_name' => get_wordcamp_name(), + 'site_url' => site_url(), + 'purchase_date' => $purchase_date, + 'ticket_type' => $ticket_type, + 'ticket_price' => $ticket_price, + 'access_link' => $access_link, + 'edit_link' => $edit_link, + 'ticket_status' => $ticket_status, + ); + + // Add a refund link if the ticket is refundable. + if ( $this->is_refundable( $attendee->ID ) ) { + $new_purchase['refund_link'] = esc_url( $this->get_refund_tickets_link( $access_token ) ); + } + + $purchase_history[] = $new_purchase; + + update_user_meta( $user_id, 'wordcamp_ticket_history', $purchase_history ); + } + } + + /** + * Update purchased ticket status on the user's profile. + * + * @param int $attendee_id The ID of the rufunded attendee. + * @param string $ticket_status Ticket status. + */ + function update_ticket_status_on_user_profile( $attendee_id, $ticket_status ) { + $user_id = get_current_user_id(); + $purchase_history = get_user_meta( $user_id, 'wordcamp_ticket_history', true ); + + // If there's no purchase history or it's not an array, nothing to udpate. + if ( ! is_array( $purchase_history ) || empty( $purchase_history ) ) { + return; + } + + foreach ( $purchase_history as $index => $ticket ) { + if ( isset( $ticket['id'] ) && intval( $ticket['id'] ) === intval( $attendee_id ) ) { + $purchase_history[ $index ]['ticket_status'] = $ticket_status; + update_user_meta( $user_id, 'wordcamp_ticket_history', $purchase_history ); + return; + } + } + } } // Initialize the $camptix global.