Created
February 11, 2018 15:36
-
-
Save Basilakis/6d04468d2939e1d3fdd197c100bc3f8b to your computer and use it in GitHub Desktop.
eventON Custom Field Functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: eventON single custom field | |
Plugin URI: https://eventon.com | |
Description: A text field for eventON submit event form | |
Author: Basilis Kanonidis | |
Version: 2.0 | |
License: GPLv2 or later | |
*/ | |
/* | |
* Config the name | |
*/ | |
define('EVENTON_SINGLE_FIELD_NAME', 'price'); | |
/* | |
* Prepare the Class | |
*/ | |
class CustomEventOnSingleTextField | |
{ | |
public function __construct() | |
{ | |
add_filter('evoau_form_fields', array($this, 'evoau_custom_fields_to_form'), 10, 1); | |
if (!is_admin()) { | |
add_action('evoau_frontform_evo'.EVENTON_SINGLE_FIELD_NAME, array($this, 'evoau_custom_fields'), 10, 6); | |
} | |
add_action('evoau_save_formfields', array($this, 'evoau_custom_save_values'), 10, 3); | |
add_shortcode('event-custom-field-value', array($this, 'get_event_custom_field_value')); | |
} | |
public function evoau_custom_fields_to_form($array) | |
{ | |
$array['evo'.EVENTON_SINGLE_FIELD_NAME] = array(ucfirst(EVENTON_SINGLE_FIELD_NAME), 'evo' . EVENTON_SINGLE_FIELD_NAME, 'evo' . EVENTON_SINGLE_FIELD_NAME, 'custom', ''); | |
return $array; | |
} | |
public function evoau_custom_fields($field, $event_id, $default_val, $EPMV, $opt2, $lang) | |
{ | |
echo "<div class='row evoau_table'><p>"; | |
$evoau_value = ($EPMV && !empty($EPMV['evoau_' . EVENTON_SINGLE_FIELD_NAME . '_value']) && $EPMV['evoau_' . EVENTON_SINGLE_FIELD_NAME . '_value'][0]) ? $EPMV['evoau_' . EVENTON_SINGLE_FIELD_NAME . '_value'][0] : ''; | |
echo '<p class="label"><label>' . ucfirst(EVENTON_SINGLE_FIELD_NAME) . '</label></p>'; | |
echo '<input type="text" id="evoau_' . EVENTON_SINGLE_FIELD_NAME . '_value" value="' . $evoau_value . '" name="evoau_' . EVENTON_SINGLE_FIELD_NAME . '_value" class="fullWidth" style="width:50%;height:19%">'; | |
echo "</p></div>"; | |
} | |
public function evoau_custom_save_values($field, $fn, $created_event_id) | |
{ | |
if ($field == 'evo' . EVENTON_SINGLE_FIELD_NAME) { | |
// for each above fields | |
foreach (array( | |
'evoau_' . EVENTON_SINGLE_FIELD_NAME . '_value', | |
) as $field) { | |
if (!empty($_POST[$field])) { | |
add_post_meta($created_event_id, $field, $_POST[$field]); | |
} | |
} | |
} | |
} | |
public static function get_eventon_custom_field_value($eventId='') | |
{ | |
if($eventId == '') { | |
$eventId = get_the_ID(); | |
} | |
$a = get_post_meta($eventId, 'evoau_' . EVENTON_SINGLE_FIELD_NAME . '_value',true); | |
if ($a) { | |
return $a; | |
} else { | |
return false; | |
} | |
} | |
public function get_event_custom_field_value($atts) | |
{ | |
extract($atts); | |
if(isset($id) && $id ) { | |
$eventId = $id; | |
} else { | |
$eventId = get_the_ID(); | |
} | |
$a = get_post_meta($eventId, 'evoau_' . EVENTON_SINGLE_FIELD_NAME . '_value',true); | |
if ($a) { | |
return $a; | |
} else { | |
return false; | |
} | |
} | |
} | |
new CustomEventOnSingleTextField(); | |
if (!function_exists('get_eventon_custom_field_value')) { | |
function get_evenon_custom_field_value($eventId='') | |
{ | |
echo CustomEventOnSingleTextField::get_eventon_custom_field_value($eventId=''); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this is what I'm looking for, to allow an attendee to add in a custom message to their ticket purchase - but, I'm not sure how to implement the code. Should this be installed as a plugin? If so, how do I hook it into EventOn so that it's available as an option?
For example, here is an event where I would like to have a text box that a customer could add a custom phrase for their art project:
https://paintedpeonydecor.com/events/farmhouse-centerpiece-box-copy/
Thanks for your help!