Skip to content

Commit

Permalink
Add default model setting
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Dec 27, 2023
1 parent e167614 commit 5283d7f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/mt-processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ function mt_registration_fields( $form, $has_data, $data, $public = 'admin' ) {
$checked = ( 'true' === get_post_meta( $event_id, '_mt_sell_tickets', true ) ) ? ' checked="checked"' : '';
$notes = get_post_meta( $event_id, '_mt_event_notes', true );
}
if ( empty( $registration ) ) {
$default_model = $options['default_model'];
$registration = $options['defaults'][ $default_model ];
}
$expiration = ( isset( $registration['reg_expires'] ) ) ? $registration['reg_expires'] : $options['defaults']['reg_expires'];
$multiple = ( isset( $registration['multiple'] ) ) ? $registration['multiple'] : $options['defaults']['multiple'];
$is_multiple = ( 'true' === $multiple ) ? 'checked="checked"' : '';
Expand Down
26 changes: 18 additions & 8 deletions src/mt-ticketing-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,21 @@ function mt_update_ticketing_settings( $post ) {
$close_type = ( isset( $post['mt_tickets_close_type'] ) ) ? $post['mt_tickets_close_type'] : 'integer';
$mt_display_remaining = ( isset( $post['mt_display_remaining'] ) ) ? $post['mt_display_remaining'] : 'proportion';
$mt_ticket_image = ( isset( $post['mt_ticket_image'] ) ) ? $post['mt_ticket_image'] : 'ticket';
$default_model = ( isset( $post['default_model'] ) ) ? $post['default_model'] : 'continuous';

$ticket_models = array( 'continuous', 'discrete', 'event' );
foreach ( $ticket_models as $model ) {
$model_defaults = ( isset( $post['defaults'][ $model ] ) ) ? $post['defaults'][ $model ] : array();
$labels = ( isset( $post['mt_label'][ $model ] ) ) ? $post['mt_label'][ $model ] : array();
$prices = ( isset( $post['mt_price'][ $model ] ) ) ? $post['mt_price'][ $model ] : array();
$close = ( isset( $post['mt_close'][ $model ] ) ) ? $post['mt_close'][ $model ] : array();
$availability = ( isset( $post['mt_tickets'][ $model ] ) ) ? $post['mt_tickets'][ $model ] : array();
$pricing_array = mt_setup_pricing( $labels, $prices, $availability, $close );
$model_defaults = ( isset( $post['defaults'][ $model ] ) ) ? $post['defaults'][ $model ] : array();
$labels = ( isset( $post['mt_label'][ $model ] ) ) ? $post['mt_label'][ $model ] : array();
$prices = ( isset( $post['mt_price'][ $model ] ) ) ? $post['mt_price'][ $model ] : array();
$close = ( isset( $post['mt_close'][ $model ] ) ) ? $post['mt_close'][ $model ] : array();
$availability = ( isset( $post['mt_tickets'][ $model ] ) ) ? $post['mt_tickets'][ $model ] : array();
$pricing_array = mt_setup_pricing( $labels, $prices, $availability, $close );

$defaults[ $model ] = $model_defaults;
$defaults[ $model ]['pricing'] = $pricing_array;
$defaults[ $model ]['tickets'] = ( is_array( $mt_total_tickets ) ) ? $mt_total_tickets[ $model ] : $mt_total_tickets;
$defaults[ $model ]['multiple'] = ( isset( $post['defaults']['multiple'] ) ) ? $post['defaults']['multiple'] : '';
$defaults[ $model ]['multiple'] = ( isset( $post['defaults']['multiple'] ) ) ? $post['defaults']['multiple'] : '';
}

/**
Expand All @@ -72,6 +73,7 @@ function mt_update_ticketing_settings( $post ) {
'mt_settings',
array(
'defaults' => $defaults,
'default_model' => $default_model,
'mt_shipping' => $mt_shipping,
'mt_handling' => $mt_handling,
'mt_ticket_handling' => $mt_ticket_handling,
Expand All @@ -91,7 +93,7 @@ function mt_update_ticketing_settings( $post ) {
$_POST
);
$settings = array_merge( get_option( 'mt_settings', array() ), $settings );
// update_option( 'mt_settings', $settings );
update_option( 'mt_settings', $settings );
/**
* Filter updated settings messages appended to the 'My Tickets Ticketing Defaults saved' message.
*
Expand Down Expand Up @@ -240,6 +242,14 @@ function mt_ticketing_settings() {
<p>
<?php _e( 'Changing these settings does not impact events that have already been created.', 'my-tickets' ); ?>
</p>
<fieldset>
<legend><?php _e( 'Default ticket model', 'my-tickets' ); ?></legend>
<ul class="checkboxes">
<li><input type="radio" name="default_model" id="default_model_continuous" value="continuous" <?php checked( $options['default_model'], 'continuous' ); ?> /> <label for="default_model_continuous"><?php _e( 'Continuous', 'my-tickets' ); ?></label></li>
<li><input type="radio" name="default_model" id="default_model_discrete" value="discrete" <?php checked( $options['default_model'], 'discrete' ); ?>/> <label for="default_model_discrete"><?php _e( 'Discrete', 'my-tickets' ); ?></label></li>
<li><input type="radio" name="default_model" id="default_model_event" value="event" <?php checked( $options['default_model'], 'event' ); ?>/> <label for="default_model_event"><?php _e( 'Event', 'my-tickets' ); ?></label></li>
</ul>
</fieldset>
<?php
$ticket_models = array( 'discrete', 'continuous', 'event' );
$tabs = '';
Expand Down
1 change: 1 addition & 0 deletions src/my-tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ function mt_default_settings() {
'discrete' => $discrete,
'event' => $showtime,
),
'default_model' => 'continuous',
'messages' => $messages,
'mt_post_types' => array( 'mc-events', 'page' ),
'mt_license_key' => '',
Expand Down

0 comments on commit 5283d7f

Please sign in to comment.