diff --git a/README.md b/README.md index 63f44c2..fb1494b 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,26 @@ function custom_tickets_additional_fields( $ticket_fields ) { 'description' => esc_html__( 'Insert the youtube embed of the video they have access to when they purchase the ticket.' ), ]; + $ticket_fields['event_date'] = [ + 'type' => 'date', + 'label' => esc_html__( 'Event date' ), + 'description' => esc_html__( 'Insert the event date.' ), + ]; + + $ticket_fields['event_type'] = [ + 'type' => 'select', + 'label' => esc_html__( 'Event type' ), + 'description' => esc_html__( 'Choose the event type.' ), + // value => label + 'options' => [ + 'workshop' => esc_html__( 'Workshop' ), + 'course' => esc_html__( 'Course'), + 'webinar' => esc_html__( 'Webinar'), + ], + // optional: + 'placeholder' => esc_html__( 'Please choose…' ), + ]; + return $ticket_fields; } @@ -117,3 +137,5 @@ function my_custom_additional_field_shortcode_printing( $html, $ticket_id, $fiel * `email` - Email (when being printed for the shortcode will add the HTML for the email link). * `number` - Number. * `checkbox` - Checkbox. +* `date` - HTML5 Date selector. +* `select` - Dropdown select. Requires an `options` array with `value => label` pairs. diff --git a/src/Tribe/Shortcodes/Tribe_Tickets_Additional_Field.php b/src/Tribe/Shortcodes/Tribe_Tickets_Additional_Field.php index 8f64f3e..b0cf780 100644 --- a/src/Tribe/Shortcodes/Tribe_Tickets_Additional_Field.php +++ b/src/Tribe/Shortcodes/Tribe_Tickets_Additional_Field.php @@ -83,6 +83,12 @@ public function get_additional_field( $ticket, $field ) { case 'email': $html = $this->get_email_render( $ticket_id, $field ); break; + case 'date': + $html = $this->get_date_render( $ticket_id, $field ); + break; + case 'select': + $html = $this->get_select_render( $ticket_id, $field ); + break; default: $html = $meta->get_field_value( $ticket_id, $meta->get_field_id( $field ), true ); } @@ -132,4 +138,74 @@ public function get_email_render( $ticket_id, $field ) { return '' . $email . ''; } + /** + * Gets the additional render, when it's Date type + * + * @param WP_Post|int $ticket the post/event we're viewing. + * @param string $field_id the additional field we want to retrieve. + * + * @return string The resulting HTML. + */ + public function get_date_render( $ticket_id, $field ) { + $meta = tribe( 'tickets.additional-fields.fields' ); + $value = $meta->get_field_value( $ticket_id, $meta->get_field_id( $field ), true ); + $value = is_string( $value ) ? trim( $value ) : ''; + + if ( $value !== '' && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $value ) ) { + try { + $dt = new \DateTimeImmutable( $value, wp_timezone() ); + $format = apply_filters( 'tribe_ext_tickets_additional_fields_date_display_format', 'd.m.Y' ); + return esc_html( $dt->format( $format ) ); + } catch ( \Exception $e ) { + return esc_html( $value ); + } + } else { + return esc_html( $value ); + } + } + + /** + * Gets the additional render, when it's Select type. + * + * @param int|WP_Post $ticket The ticket. + * @param string $field Field key. + * + * @return string + */ + public function get_select_render( $ticket_id, $field ) { + $meta = tribe( 'tickets.additional-fields.fields' ); + + $field_id = $meta->get_field_id( $field ); + $value = $meta->get_field_value( $ticket_id, $field_id, true ); + $value = is_string( $value ) ? trim( $value ) : ''; + + if ( $value === '' ) { + return ''; + } + + // Feld-Definitionen über den bekannten Filter holen. + $fields = apply_filters( 'tribe_ext_tickets_additional_fields', [] ); + + if ( isset( $fields[ $field ]['options'][ $value ] ) ) { + $label = $fields[ $field ]['options'][ $value ]; // Label aus options + } else { + $label = $value; // Fallback: Key direkt + } + + /** + * Filter the output of select field additional field. + */ + $label = apply_filters( + 'tribe_ext_tickets_additional_fields_select_display', + $label, + $ticket_id, + $field, + $value + ); + + return esc_html( (string) $label ); + } + + + } diff --git a/src/admin-views/editor/input-date.php b/src/admin-views/editor/input-date.php new file mode 100644 index 0000000..7d165f6 --- /dev/null +++ b/src/admin-views/editor/input-date.php @@ -0,0 +1,32 @@ + +
+ +
+ +