diff --git a/admin.js b/admin.js index 2a3be8e..b2c170d 100644 --- a/admin.js +++ b/admin.js @@ -160,6 +160,7 @@ window.camptix = window.camptix || { models: {}, views: {}, collections: {} }; question: '', values: '', required: false, + include_in_email: false, order: 0, json: '' } @@ -427,7 +428,8 @@ window.camptix = window.camptix || { models: {}, views: {}, collections: {} }; // Make sure post_id and required are correct types, not integers. question.set( { post_id: parseInt( question.get( 'post_id' ), 10 ), - required: !! parseInt( question.get( 'required' ), 10 ) + required: !! parseInt( question.get( 'required' ), 10 ), + include_in_email: !! parseInt( question.get( 'include_in_email' ), 10 ) }, { silent: true } ); var found = camptix.questions.where( { post_id: parseInt( question.get( 'post_id' ), 10 ) } ); diff --git a/camptix.php b/camptix.php index 115dbd2..fad8a82 100644 --- a/camptix.php +++ b/camptix.php @@ -1400,6 +1400,7 @@ protected function run_upgrade_parts( $from ) { // Save attributes, including the key for future use. update_post_meta( $question_id, 'tix_values', $question['values'] ); update_post_meta( $question_id, 'tix_required', $question['required'] ); + update_post_meta( $question_id, 'tix_include_in_email', $question['include_in_email'] ); update_post_meta( $question_id, 'tix_type', $question['type'] ); update_post_meta( $question_id, 'tix_key', $key ); @@ -4293,6 +4294,14 @@ function metabox_ticket_questions() { + + + + + + + +

@@ -4322,6 +4331,7 @@ function metabox_ticket_questions() { + @@ -4368,6 +4378,7 @@ function metabox_ticket_questions() { type: 'ID, 'tix_type', true ) ); ?>', question: 'post_title ) ); ?>', required: ID, 'tix_required', true ) ); ?>, + include_in_email: ID, 'tix_include_in_email', true ) ); ?>, values: 'ID, 'tix_values', true ) ) ); ?>' } ) ); @@ -4643,9 +4654,11 @@ function save_ticket_post( $post_id ) { 'type' => $question['type'], 'values' => $question_values, 'required' => isset( $question['required'] ), + 'include_in_email' => isset( $question['include_in_email'] ), ); $clean_question['required'] = (bool) $question['required']; + $clean_question['include_in_email'] = (bool) $question['include_in_email']; $question = $clean_question; unset( $clean_question ); @@ -4677,6 +4690,7 @@ function save_ticket_post( $post_id ) { // Question meta update_post_meta( $question_id, 'tix_values', $question['values'] ); update_post_meta( $question_id, 'tix_required', $question['required'] ); + update_post_meta( $question_id, 'tix_include_in_email', $question['include_in_email'] ); update_post_meta( $question_id, 'tix_type', $question['type'] ); // Don't add duplicate questions to the ticket/order. @@ -5501,11 +5515,12 @@ function form_attendee_info() { ID ); - $value = isset( $this->form_data['tix_attendee_questions'][ $i ][ $question->ID ] ) ? $this->form_data['tix_attendee_questions'][ $i ][ $question->ID ] : ''; - $type = get_post_meta( $question->ID, 'tix_type', true ); - $required = get_post_meta( $question->ID, 'tix_required', true ); - $class_name = 'tix-row-question-' . $question->ID; + $name = sprintf( 'tix_attendee_questions[%d][%s]', $i, $question->ID ); + $value = isset( $this->form_data['tix_attendee_questions'][ $i ][ $question->ID ] ) ? $this->form_data['tix_attendee_questions'][ $i ][ $question->ID ] : ''; + $type = get_post_meta( $question->ID, 'tix_type', true ); + $required = get_post_meta( $question->ID, 'tix_required', true ); + $include_in_email = get_post_meta( $question->ID, 'tix_include_in_email', true ); + $class_name = 'tix-row-question-' . $question->ID; ?> @@ -5853,11 +5868,12 @@ function form_edit_attendee() { 1 ), (int) $ticket_id, 1, $questions ) ) : ?> ID ); - $value = isset( $answers[ $question->ID ] ) ? $answers[ $question->ID ] : ''; - $type = get_post_meta( $question->ID, 'tix_type', true ); - $required = get_post_meta( $question->ID, 'tix_required', true ); - $class_name = 'tix-row-question-' . $question->ID; + $name = sprintf( 'tix_ticket_questions[%d]', $question->ID ); + $value = isset( $answers[ $question->ID ] ) ? $answers[ $question->ID ] : ''; + $type = get_post_meta( $question->ID, 'tix_type', true ); + $required = get_post_meta( $question->ID, 'tix_required', true ); + $include_in_email = get_post_meta( $question->ID, 'tix_include_in_email', true ); + $class_name = 'tix-row-question-' . $question->ID; ?> @@ -7127,7 +7143,44 @@ function email_tickets( $payment_token = false, $from_status = 'draft', $to_stat if ( isset( $order['coupon'] ) && $order['coupon'] ) $receipt_content .= sprintf( '* ' . __( 'Coupon used: %s', 'camptix' ) . "\n", $order['coupon'] ); - $receipt_content .= sprintf( "* " . __( 'Total: %s', 'camptix' ), $this->append_currency( $order['total'], false ) ); + $receipt_content .= sprintf( "* " . __( 'Total: %s', 'camptix' )."\n", $this->append_currency( $order['total'], false ) ) ; + $receipt_content .= "\n\n"; + + foreach ( $order['items'] as $item ) { + + $question_ids = (array) get_post_meta( $item['id'], 'tix_question_id' ); + $order = (array) get_post_meta( $item['id'], 'tix_questions_order', true ); + + // Make sure we have at least some questions + if ( empty( $question_ids ) ) + return array(); + + $questions = get_posts( array( + 'post_type' => 'tix_question', + 'post_status' => 'publish', + 'posts_per_page' => -1, + 'post__in' => $question_ids, + ) ); + + foreach ( $attendees as $attendee ) { + $answers = get_post_meta( $attendee->ID, 'tix_questions', true ); + foreach ( $questions as $question ) { + // if question is to be included in email + $include_in_email = get_post_meta( $question->ID, 'tix_include_in_email', true ); + if ( $include_in_email ) { + // grab the questions name + $question_name = $question->post_title; + // grab the value from the attendee post meta + $answer = $answers[$question->ID]; + // append them to receipt content + $receipt_content .= esc_html( $question_name.': '.$answer )."\n"; + } + } + break; + } + + } + $signature = apply_filters( 'camptix_ticket_email_signature', __( 'Let us know if you have any questions!', 'camptix' ) ); // Set the tmp receipt for shortcodes use.