Okay
  Public Ticket #2128423
Location Management
Closed

Comments

  • ajacks started the conversation

    Hi there,

    Quick question: how do I restrict the city and country to those added at the back end? 

    When a user is submitting an event in the front end - he/she can provide locations only for pre-defined city/country. Say for e.g. my location is London, UK. Then all events need to be restricted for London, UK only...

    How can I achieve this? I wasn't sure so asking here...

  •  877
    Zhivko replied

    Hi,

    Add this filter in your theme functions.php file:

    add_filter('stec_builder_front_elements', function($elements) {
        if (isset($elements['location'])) {
            $location = $elements['location'];
            if (isset($location[0])) {
                $options = array();
                $locations = \Stachethemes\Stec\Locations::get_locations_list();
                $options[] = "<optgroup label='" . esc_attr__('Locations', 'stec') . "'>";
                $options[] = "<option selected value=''>" . esc_html__('No location', 'stec') . "</option>";
                foreach ($locations as $k => $v) :
                    $options[] = "<option value='{$k}'>{$v}</option>";
                endforeach;
                $options[]   = "</optgroup>";
                $location[0] = sprintf("<select {{params}} name='location'>%s</select>", implode(PHP_EOL, $options));
            }
            $elements['location'] = $location;
        }     return $elements;
    });

    Stachethemes Developer

  • ajacks replied

    Hi Zhivko,

    thanks for this... but an issue remains... I want to only fix the city and country.... the user still needs to be able to add the actual address of the event... based on the code you shared no location details can be added... only city and country can be selected....

    Use Case

    1. Admin has restricted the City & Country for front end submissions of an event
    2. User adds event details and location address for an event in the restricted city
    3. Event attendee is able to filter the calendar for a City based events and not all addresses...

    How can I achieve this please....