fast_events_input fields
This filter is called after a basic check of all input and ticket fields.
1<?php
2function your_filter_input_fields( $attr ) {
3 // Do your manipulation here
4 return $attr;
5}
6
7add_filter( 'fast_events_input_fields', 'your_filter_input_fields', 10, 1 );
Parameters
- $attr[‘id’]
(int) The id of the event. This value is read-only.
- $attr[‘name’]
(string) The name of the person placing the order.
- $attr[‘email’]
(string) The emailaddress of the person placing the order. This value is read-only.
- $attr[‘total’]
(string) The total order value. For example
6.50
. This value is read-only.- $attr[‘total_vat’]
(string) The total order VAT value. For example
2.50
. This value is read-only.- $attr[‘fields’]
array of input fields.
‘name’ (string, case sensitive) The name of the input field.
‘value’ (string) The value of the input field.
- $attr[‘tickets’]
array of ticket-types ordered.
‘name’ (string, case sensitive) The name of the ticket-type.
‘price’ (string) The ticket price. Example
6.25
.‘vat’ (string) VAT.
‘count’ (int) The number of tickets ordered.
Return
- $attr
A filter can add an
errors
attribute to$attr
. So for example$attr['errors'] = 'Wrong value'
. Fast Events will check and stop processing the order by returning the error. See the Check password example.
Changelog
Version |
Description |
---|---|
1.0 |
Introduced. |
Examples
Discount between dates
Give a discount of 10% (in this example; see the 0.9) on every ticket-type between 2 dates.
1<?php
2function your_filter_input_fields( $attr ) {
3 if ( time() > strtotime('2019-12-10 00:00:00') && time() < strtotime('2019-12-24 18:00:00') ) {
4 foreach ( $attr['tickets'] as $key => $value ) {
5 $attr['tickets'][$key]['price'] = number_format( 0.9 * (float) $value['price'], 2, '.', '' );
6 }
7 }
8 return $attr;
9}
10
11add_filter( 'fast_events_input_fields', 'your_filter_input_fields', 10, 1 );
Discount if more than 3 tickets
Give a discount of 20% if you order more than 3 Silver
tickets.
1<?php
2function your_filter_input_fields_2( $attr ) {
3 foreach ( $attr['tickets'] as $key => $value ) {
4 if ( 'Silver' === $value['name'] && 3 < $value['count'] ) {
5 $attr['tickets'][$key]['price'] = number_format( 0.8 * (float) $value['price'], 2, '.', '' );
6 }
7 }
8 return $attr;
9}
10
11add_filter( 'fast_events_input_fields', 'your_filter_input_fields_2', 10, 1 );
Free ticket
Get 1 free Silver
ticket if you order 2 or more Gold (Backstage)
tickets.
1<?php
2function your_filter_input_fields_3( $attr ) {
3 foreach ( $attr['tickets'] as $key => $value ) {
4 if ( 'Gold (Backstage)' === $value['name'] && 2 <= $value['count'] ) {
5 $silver_key = array_search('Silver', array_column($attr['tickets'], 'name'));
6 $old_total = $attr['tickets'][$silver_key]['count'] * (float) $attr['tickets'][$silver_key]['price'];
7 $new_price = $old_total / ( $attr['tickets'][$silver_key]['count'] + 1 );
8 $attr['tickets'][$silver_key]['price'] = number_format( $new_price, 2, '.', '' );
9 $attr['tickets'][$silver_key]['count']++;
10 }
11 }
12 return $attr;
13}
14
15add_filter( 'fast_events_input_fields', 'your_filter_input_fields_3', 10, 1 );
Check password
Check the password against a database table. This requires you to define an input field Password
that is used in this snippet. A wrong password or a non-existing user will result in an error. Finding the user is done with the emailaddress.
1<?php
2function your_filter_input_fields_4( $attr ) {
3 // Search for user
4 $user = $wpdb->get_row( $wpdb->prepare( "SELECT password FROM put_your_tablename_here WHERE email = '%s'", $attr['email'] ) );
5 if ( empty( $user ) ) {
6 $attr['errors'] = 'Unknown user';
7 return $attr;
8 }
9
10 $pwd_key = array_search('Password', array_column($attr['fields'], 'name'));
11 if ( ! password_verify( $attr['fields'][$pwd_key]['value'], $user->password ) ) {
12 $attr['errors'] = 'Wrong password';
13 }
14 return $attr;
15}
16
17add_filter( 'fast_events_input_fields', 'your_filter_input_fields_4', 10, 1 );