\WP_Stager_Integration\Component::render_event_location(): void

Description

Render the event location component.

Returns:

void

Information

Fileclass-component.php line 480

Full Code

/**
 * Render the event location component.
 *
 * @return void
 */
public static function render_event_location() {

    // Get data
    $event    = (array) (Event::get_single_event_data() ?: array());
    $location = (array) ($event[ 'location' ] ?? array());

    // Process location data
    $location_name         = (string) ($location[ 'name' ] ?? '');
    $location_city         = (string) ($location[ 'city' ] ?? '');
    $location_street       = (string) ($location[ 'street' ] ?? '');
    $location_zipcode      = (string) ($location[ 'zipcode' ] ?? '');
    $location_country      = (string) ($location[ 'country' ] ?? '');
    $location_country_name = (string) (\WP_Stager_Integration\Admin::get_countries()[ $location_country ] ?? '');
    $location_phone        = (string) ($location[ 'phoneNumber' ] ?? '');
    $location_url          = (string) ($location[ 'url' ] ?? '');
    $location_latitude     = (string) ($location[ 'latitude' ] ?? '');
    $location_longitude    = (string) ($location[ 'longitude' ] ?? '');
    $location_spaces       = (array) ($location[ 'spaces' ] ?? array());
    $location_spaces_names = wp_list_pluck( $location_spaces, 'name' );

    // Define Google Maps URL
    if ( $location_street && $location_city && $location_country_name ) {
        $google_maps_url = 'https://www.google.com/maps/search/?api=1&query=' . urlencode( $location_street . ', ' . $location_zipcode . ', ' . $location_city . ', ' . $location_country_name );
    } else if ( $location_latitude && $location_longitude ) {
        $google_maps_url = "https://maps.google.com/?q=$location_latitude,$location_longitude";
    } else {
        $google_maps_url = '';
    }

    // Render the component
    self::render( 'event-location', 'template-parts/event-page', array(
        'name'            => $location_name,
        'city'            => $location_city,
        'street'          => $location_street,
        'zipcode'         => $location_zipcode,
        'country_name'    => $location_country_name,
        'phone'           => $location_phone,
        'url'             => $location_url,
        'google_maps_url' => $google_maps_url,
    ) );
}

💡 If you ever get stuck or have a question, please check our FAQs, our Free Integration Service, our paid Full Integration Service, or reach out to us!

Get WP Stager Integration

🎁 Limited offer: Use code WELCOME26 to get your first month for free!