Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Include in email option for fields #186

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ window.camptix = window.camptix || { models: {}, views: {}, collections: {} };
question: '',
values: '',
required: false,
include_in_email: false,
order: 0,
json: ''
}
Expand Down Expand Up @@ -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 ) } );
Expand Down
75 changes: 64 additions & 11 deletions camptix.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -4293,6 +4294,14 @@ function metabox_ticket_questions() {
<label><input data-model-attribute="required" data-model-attribute-type="checkbox" id="tix-add-question-required" type="checkbox" value="1" /> <?php _e( 'This field is required', 'camptix' ); ?></label>
</td>
</tr>
<tr valign="top">
<th scope="row">
<label><?php _e( 'Include in Email', 'camptix' ); ?></label>
</th>
<td>
<label><input data-model-attribute="include_in_email" data-model-attribute-type="checkbox" id="tix-add-question-include_in_email" type="checkbox" value="1" /> <?php _e( 'Include this field in the email confirmation', 'camptix' ); ?></label>
</td>
</tr>
</table>
<p class="submit">
<a href="#" class="button tix-add"><?php _e( 'Add Question', 'camptix' ); ?></a>
Expand Down Expand Up @@ -4322,6 +4331,7 @@ function metabox_ticket_questions() {
<input type="hidden" data-model-attribute="type" value="<?php echo esc_attr( get_post_meta( $question->ID, 'tix_type', true ) ); ?>" />
<input type="hidden" data-model-attribute="question" value="<?php echo esc_attr( $question->post_title ); ?>" />
<input type="hidden" data-model-attribute="required" value="<?php echo intval( get_post_meta( $question->ID, 'tix_required', true ) ); ?>" />
<input type="hidden" data-model-attribute="include_in_email" value="<?php echo intval( get_post_meta( $question->ID, 'tix_include_in_email', true ) ); ?>" />
<input type="hidden" data-model-attribute="values" value="<?php echo esc_attr( implode( ', ', (array) get_post_meta( $question->ID, 'tix_values', true ) ) ); ?>" />
</label>
</li>
Expand Down Expand Up @@ -4368,6 +4378,7 @@ function metabox_ticket_questions() {
type: '<?php echo esc_js( get_post_meta( $question->ID, 'tix_type', true ) ); ?>',
question: '<?php echo esc_js( apply_filters( 'the_title', $question->post_title ) ); ?>',
required: <?php echo esc_js( (int) (bool) get_post_meta( $question->ID, 'tix_required', true ) ); ?>,
include_in_email: <?php echo esc_js( (int) (bool) get_post_meta( $question->ID, 'tix_include_in_email', true ) ); ?>,
values: '<?php echo esc_js( implode( ', ', (array) get_post_meta( $question->ID, 'tix_values', true ) ) ); ?>'
} ) );
<?php endforeach; ?>
Expand Down Expand Up @@ -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 );

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -5501,11 +5515,12 @@ function form_attendee_info() {
<?php foreach ( $questions as $question ) : ?>

<?php
$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 );
$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;
?>

<tr class="<?php echo esc_attr( $class_name ); ?>">
Expand Down Expand Up @@ -5853,11 +5868,12 @@ function form_edit_attendee() {
<?php if ( apply_filters( 'camptix_ask_questions', true, array( (int) $ticket_id => 1 ), (int) $ticket_id, 1, $questions ) ) : ?>
<?php foreach ( $questions as $question ) : ?>
<?php
$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 );
$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;
?>

<tr class="<?php echo esc_attr( $class_name ); ?>">
Expand Down Expand Up @@ -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.
Expand Down