Skip to content

Instantly share code, notes, and snippets.

@Basilakis
Created February 11, 2018 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Basilakis/6d04468d2939e1d3fdd197c100bc3f8b to your computer and use it in GitHub Desktop.
Save Basilakis/6d04468d2939e1d3fdd197c100bc3f8b to your computer and use it in GitHub Desktop.
eventON Custom Field Functionality
<?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='');
}
}
@bdwatt0
Copy link

bdwatt0 commented May 29, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment