How to add a pre-existing ticket to an event?

Home Forums Ticket Products Event Tickets Plus How to add a pre-existing ticket to an event?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #965592
    foxrobinson
    Participant

    I have already set up my ticket product in Woocommerce and now want to add them to an event. There seems no way to do this though as when I click ‘Add New Tickket’ I am asked to create a new ticket product. Even if I name the ticket the same as a currently existing one, I just end up with a duplicate.

    #965774
    Nico
    Member

    Hi foxrobinson,

    Thanks for hitting the forums, hopefully I can help you with your inquire. First of all I’m sorry to say there is no “easy way” of doing this. Let me explain how this works.

    Basically what links an event to a product (ticket) is the product meta field _tribe_wooticket_for_event. It stores the value of the associated event ID. One way of editing/adding this value is to edit the post_meta table in the database. The SQL query to add the meta value (using default table prefix) should look like this:

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

    Do you feel comfortable doing it this way? In case you don’t please let me know and we’ll try another way.

    Thanks,
    Nico

    #965951
    foxrobinson
    Participant

    That blows my mind! So the only way to add a ticket to an event in your plugin, is to go into my database and edit it? You have got to be kidding me. Im a WordPress developer and have only a little experience with editing databses. Nor am I willing to do this on a live site.

    How can it be done through the WordPress interface given that I paid for a WordPress plugin.

    #966019
    Nico
    Member

    Hi foxrobinson,

    Thanks for the follow up! I’m sorry this isn’t a feature of our plugin at the time, as you say it’s something that users might expect to have out of the box. Also sorry for assuming that you would be comfortable with the database approach. Let’s try a less technical way around to achieve this.

    Please follow this steps:

    1- Find the Product ID, of the existing product you want to link to the event.
    (ID’s are present in the URL when you edit the product in WP-Admin, e.g: for this URL ‘…/post.php?post=21&action=edit’, Product ID is 21)

    2- Find the corresponding Event ID.
    (You can find the Event ID in the URL while editing the event, just the same way as in step 1)

    3- Paste this code in your ‘functions’ file, located at ‘wp-content/themes/<your_theme>/functions.php’.


    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 );
    }
    }

    4- Add this line below the pasted function, replacing <product_id> and <event_id> for the actual values. Add as many lines as needed.


    tribe_link_product_event(<product_id>,<event_id>);

    5- Navigate to the Event Page in WP-Admin and check if the ticket got linked.

    6- Ready! Now you can comment out or delete the lines added in step 4.

    Just in case you need to un-link a ticket from an event (but don’t want to delete it), you can repeat these steps, but adding this other function in step 3 and using it in step 4:


    // add this function in step 3
    function tribe_unlink_product_event ( $product_id, $event_id ) {
    delete_post_meta($product_id, '_tribe_wooticket_for_event', $event_id);
    }
    // use it this way in step 4
    tribe_unlink_product_event(<product_id>,<event_id>);

    That should do the trick, please let me know how this goes.

    Thanks,
    Nico

    PS: It would be great if you could suggest this as a feature idea at our Uservoice page, this way other users can up-vote it and ultimately it can be included in our product development roadmap.

    #966136
    foxrobinson
    Participant

    Hi Nico,

    Yes thats more my style and that worked for me. I have requested this as a feature at the Uservoice page.

    Thank you for your help,

    David

    #966165
    Nico
    Member

    Glad to hear David 🙂

    Thanks for the feature request in Uservoice. You rock!

    I’m going to close this topic – but please don’t hesitate to create new topics if you need help with anything else. Have a great weekend,
    Nico

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘How to add a pre-existing ticket to an event?’ is closed to new replies.