Skip to content Skip to sidebar

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 17:00 10:00 – 17:00 10:00 – 17:00 10:00 – 17:00 10:00 – 17:00 -
- 18:00 – 19:00 18:00 – 19:00 18:00 – 19:00 18:00 – 19:00 18:00 – 19:00 -

Supporter timezone: Asia/Kathmandu (GMT+05:45)

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Shekhar Bhandari 1 year, 1 month ago.

Assisted by: Shekhar Bhandari.

Author Posts
September 3, 2024 at 7:09 am #16134102

markusT-21

Background of the issue:
I use WP Eventmanager Pro for event listing and user registrations for events. I add an event in German. The event has 8 registration spots. I have set automatic translation to English.

Symptoms:
The event is not just translated, it's being copied. So there are now two different events, with each 8 slots for registrations. It should be just 1 event (in German, translated to English) with 8 slots overall.

Questions:
What do I have to change to ensure that the event is translated and not duplicated?

September 3, 2024 at 7:54 am #16134266

markusT-21

I've added a event and translated it to french, but the preview link won't work:
hidden link

September 3, 2024 at 8:26 am #16134441

markusT-21

Link is working now.

And problem is the same as on my page:

English - 4 spots left (1 registered):
hidden link

French - 5 spots left:
hidden link

September 3, 2024 at 8:42 am #16134520

Shekhar Bhandari
WPML Supporter since 03/2015

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello,

I've noticed the issue and have escalated it to our compatibility team. I'll keep you informed as soon as I receive any feedback from them.

Thank you.

September 19, 2024 at 7:43 am #16196434

markusT-21

Hi,
any update on this task?
regards Johanna

September 19, 2024 at 8:03 am #16196680

Shekhar Bhandari
WPML Supporter since 03/2015

Languages: English (English )

Timezone: Asia/Kathmandu (GMT+05:45)

Hello there,

Our compatibility team checked the issue and suggested the following workaround:

Open app/public/wp-content/plugins/wp-event-manager-registrations/wp-event-manager-registrations-functions.php

Around line 497, replace the following snippet:

if(!function_exists('get_event_registration_count')) {
    /**
     * Get number of registrations for a event
     * @param  int $event_id
     * @return int
     */
    function get_event_registration_count($event_id) {
        return sizeof(get_posts(array(
            'post_type'      => 'event_registration',
            'post_status'    => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
            'posts_per_page' => -1,
            'fields'         => 'ids',
            'post_parent'    => $event_id
        )));
    }
}

With

if(!function_exists('get_event_registration_count')) {
    /**
     * Get number of registrations for a event
     * @param  int $event_id
     * @return int
     */
    function get_event_registration_count($event_id) {
        
        // WPML workaround for compsupp-7562 - Part I
        $translations = apply_filters( 'wpml_get_element_translations', null, $event_id, 'post_' . get_post_type($event_id) );
        
        // Extract the IDs of the translated posts
        $event_ids = array_map(function($translation) {
            return $translation->element_id;
        }, $translations);
    
        // Get event registrations for all translations
        return sizeof(get_posts(array(
            'post_type'      => 'event_registration',
            'post_status'    => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
            'posts_per_page' => -1,
            'fields'         => 'ids',
            'post_parent__in' => $event_ids // Get all registrations for the event IDs
        )));
    }
    
}

Then, around line 595, replace the following snippet:

if(!function_exists('user_has_registered_for_event')) {
    /**
     * See if a user has already appled for a event
     * @param  int $user_id, $event_id
     * @return int
     */
    function user_has_registered_for_event($user_id, $event_id) {
        if(!$user_id) {
            return false;
        }
        return sizeof(get_posts(array(
            'post_type'      => 'event_registration',
            'post_status'    => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
            'posts_per_page' => 1,
            'fields'         => 'ids',
            'post_parent'    => $event_id,
            'meta_query'     => array(
                array(
                    'key' => '_attendee_user_id',
                    'value' => absint($user_id)
                )
            )
        )));
    }
}

With

if(!function_exists('user_has_registered_for_event')) {
    /**
     * See if a user has already appled for a event
     * @param  int $user_id, $event_id
     * @return int
     */
    function user_has_registered_for_event($user_id, $event_id) {
        if(!$user_id) {
            return false;
        }

        // WPML Workaround for compsupp-7562 - Part II
        $translations = apply_filters( 'wpml_get_element_translations', null, $event_id, 'post_' . get_post_type($event_id) );
        
        // Extract the IDs of the translated posts
        $event_ids = array_map(function($translation) {
            return $translation->element_id;
        }, $translations);

        // Check if the user is registered for any translation of the event
        return sizeof(get_posts(array(
            'post_type'      => 'event_registration',
            'post_status'    => array_merge(array_keys(get_event_registration_statuses()), array('publish')),
            'posts_per_page' => 1,
            'fields'         => 'ids',
            'post_parent__in' => $event_ids, // Check all event translations
            'meta_query'     => array(
                array(
                    'key'   => '_attendee_user_id',
                    'value' => absint($user_id)
                )
            )
        ))) > 0;
    }

}

Let me know if this helps.

Thanks

The topic ‘[Closed] Events are duplicated not just translated’ is closed to new replies.