Link a new event to an existing ticket

Home Forums Ticket Products Event Tickets Plus Link a new event to an existing ticket

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1002715
    xrossglobalgroup
    Participant

    Hello, I previously posted the following forum: https://theeventscalendar.com/support/forums/topic/link-event-to-existing-ticket/

    My developer is not able to figure out what to do and wanted to know this:

    We are trying to add an existing Woo Commerce product to a new event, without actually creating a new Woo commerce product in that event (lower part of the backend). In which table should we add the entry for a particular event?

    Thanks for your help.

    #1002728
    Nico
    Member

    Hi there @xrossglobalgroup,

    Glad to help you once again on this one!

    The table that links the event with the ticket is the wp_postmeta table. The SQL code to create that link is the following:

    INSERT INTO wp_postmeta ('meta_id', 'post_id', 'meta_key', 'meta_value) VALUES (NULL, -PRODUCT_ID-, '_tribe_wooticket_for_event', -EVENT_ID-);

    You can achieve the same thing via PHP, using the following code:

    function tribe_link_product_event ( $product_id, $event_id ) {
    if ( !in_array($event_id, get_post_meta( $product_id, '_tribe_wooticket_for_event')) ) {
    add_post_meta( $product_id, '_tribe_wooticket_for_event', $event_id );
    }
    }

    Please let me know if this helps you getting it sorted out,
    Best,
    Nico

    #1002777
    xrossglobalgroup
    Participant

    This reply is private.

    #1003218
    Nico
    Member

    Hi Edgar,

    Thanks for following up on this. Unfortunately we are not allowed to log into client sites to make changes 🙁

    Can you test this out once again please? I just tested it in my local install and it’s working.

    This can be used in more elegant/functional ways, but just to test if this works at all on your end, add this snippet to your theme’s functions.php file -located at wp-content/themes/your_theme/ :

    add_action( 'admin_init', 'link_product_with_tickets' );

    function link_product_with_tickets ( ){
    tribe_link_product_event ( replace_with_ticket_id , replace_with_event_id );
    }

    function tribe_link_product_event ( $product_id, $event_id ) {
    if ( !in_array($event_id, get_post_meta( $product_id, '_tribe_wooticket_for_event')) ) {
    add_post_meta( $product_id, '_tribe_wooticket_for_event', $event_id );
    }
    }

    Make sure to replace the sample strings with the corresponding id’s (just the number). Once the code is in place go to edit page of the event in the back-end and refresh. After doing so you should see the ticket linked.

    Please let me know about this test,
    Best,
    Nico

    #1008243
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Link a new event to an existing ticket’ is closed to new replies.