How to get the ticket title?

Home Forums Ticket Products Event Tickets Plus How to get the ticket title?

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #1133862
    James
    Participant

    I’m trying to get the ticket title. My code is below. I’ve got it getting the venue title succesfully as per help from a previous forum post, so tried to do it the same way but no luck.

    /* attach a word doc with each purchase. */
    function attach_doc_to_email ( $attachments , $event_id, $object ) {

    // get the tickets
    $main = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
    $tickets = $main->get_tickets( $event_id );

    // Get ticket title - not yet complete
    $ticket_id = tribe_get_ticket_id( $event_id );
    $ticket_info = get_post( $ticket_id );
    $ticket_title = get_the_title( $ticket_id );

    //Get the venue name
    $venue_id = tribe_get_venue_id( $event_id );
    $venue_info = get_post( $venue_id );
    $venue_title = get_the_title( $venue_id );

    if (strpos($ticket_title, 'SSSTS') !== false) {

    $your_doc_path = get_template_directory() . '/instructions/chelmsford-sssts.docx';

    }else{

    $your_doc_path = get_template_directory() . '/instructions/chelmsford-health-safety-awareness.docx';
    }

    $attachments[] = $your_doc_path;
    return $attachments;
    }

    So basically the only bit of code that isn’t working is where I’ve attempted to get the ticket title. The ticket I’m testing with is called “2 Day SSSTS Chelmsford”. Any help getting the title is greatly appreaciated.

    #1134262
    Cliff
    Member

    Hi James.

    Thanks for providing your code snippet.

    Could you please specify which ticket type(s) you’re trying to get (e.g. RSVP, WooCommerce, EDD) — or list the titles of all tickets attached to a specific event regardless of ticket type?

    Could you also specify where you’re trying to display this information (e.g. Event Single page, custom shortcode, email)?

    Thank you.

    #1134379
    James
    Participant

    It is a Woocommerce one. I am trying to get the title name of the ticket itself, not the event. I am doing this in my functions.php, which defines which attachment goes with the e-mail. So if the title contains “SSSTS” in the title, then the SSSTS word doc should be attached.

    I already have the venue checker working so this title checker will go alongside the venue to give the absolute correct word doc.

    #1134713
    Cliff
    Member

    Thanks for that information.

    I’m uncertain exactly where you’re getting the information and how you’ll be using it, but if you have the $ticket object, you can use $ticket->name, as is done on Line 89 of /wp-content/plugins/event-tickets-plus/src/views/wootickets/tickets.php

    Please let me know if you need additional assistance.

    #1134743
    James
    Participant

    This doesn’t do the job – that file is using a “foreach” loop. I’ve set it up similar to that but then the word doc stops getting attached altogether. Is there a different way to get the ticket title?

    The venue title is retrieved with the code I showed earlier. Can the title not be found a similar way? This should be only checking the one ticket as it is the one that is being bought at the checkout (as it’s using the event id).

    If the ticket title cannot be found, can the event title be found instead? (Using the code I posted earlier)

    #1135145
    Cliff
    Member

    I see you have this line of code and I’m guessing it’s working since there’s not a comment around it stating it’s not:

    $tickets = $main->get_tickets( $event_id );

    So if you var_dump( $tickets ); is the information you’re wanting in there somewhere?

    #1135356
    James
    Participant

    The information I want is in there. I’ll post the var_dump result below, but it looks like it’s in a bit called [“name”] but how to get this?

    array(9) { [0]=> object(Tribe__Tickets__Ticket_Object)#4473 (20) { ["ID"]=> int(308) ["name"]=> string(22) "2 Day SSSTS Chelmsford" ["description"]=> string(0) "" ["price"]=> string(3) "265" ["regular_price"]=> string(3) "265" ["on_sale"]=> bool(false) ["admin_link"]=> string(42) "http://ssstsuk.co.uk/wp-admin/&action=edit" ["frontend_link"]=> string(64) "http://ssstsuk.co.uk/1-day-health-safety-awareness-chelmsford-2/" ["provider_class"]=> string(48) "Tribe__Tickets_Plus__Commerce__WooCommerce__Main" ["provider":protected]=> NULL ["stock":protected]=> int(0) ["global_stock_mode":protected]=> string(3) "own" ["global_stock_cap":protected]=> int(0) ["qty_sold":protected]=> int(11) ["qty_pending":protected]=> int(0) ["qty_cancelled":protected]=> int(0) ["manage_stock":protected]=> bool(false) ["start_date"]=> string(19) "2016-06-20 08:00:00" ["end_date"]=> string(19) "2016-07-20 17:00:00" ["purchase_limit"]=> string(1) "0" } [1]=> object(Tribe__Tickets__Ticket_Object)#4651 (20) { ["ID"]=> int(306) ["name"]=> string(46) "1 Day Health & Safety Awareness Chelmsford" ["description"]=> string(0) "" ["price"]=> string(3) "135" ["regular_price"]=> string(3) "135" ["on_sale"]=> bool(false) ["admin_link"]=> string(42) "http://ssstsuk.co.uk/wp-admin/&action=edit" ["frontend_link"]=> string(62) "http://ssstsuk.co.uk/1-day-health-safety-awareness-chelmsford/" ["provider_class"]=> string(48) "Tribe__Tickets_Plus__Commerce__WooCommerce__Main" ["provider":protected]=> NULL ["stock":protected]=> int(0) ["global_stock_mode":protected]=> string(3) "own" ["global_stock_cap":protected]=> int(0) ["qty_sold":protected]=> int(0) ["qty_pending":protected]=> int(0) ["qty_cancelled":protected]=> int(0) ["manage_stock":protected]=> bool(false) ["start_date"]=> string(19) "2016-06-20 08:00:00" ["end_date"]=> string(19) "2016-07-19 17:00:00" ["purchase_limit"]=> string(1) "0" } [2]=> object(Tribe__Tickets__Ticket_Object)#4581 (20) { ["ID"]=> int(304) ["name"]=> string(46) "1 Day Health & Safety Awareness Colchester" ["description"]=> string(0) "" ["price"]=> string(3) "150" ["regular_price"]=> string(3) "150" ["on_sale"]=> bool(false) ["admin_link"]=> string(42) "http://ssstsuk.co.uk/wp-admin/&action=edit" ["frontend_link"]=> string(62) "http://ssstsuk.co.uk/1-day-health-safety-awareness-colchester/" ["provider_class"]=> string(48) "Tribe__Tickets_Plus__Commerce__WooCommerce__Main" ["provider":protected]=> NULL ["stock":protected]=> int(0) ["global_stock_mode":protected]=> string(3) "own" ["global_stock_cap":protected]=> int(0) ["qty_sold":protected]=> int(0) ["qty_pending":protected]=> int(0) ["qty_cancelled":protected]=> int(0) ["manage_stock":protected]=> bool(false) ["start_date"]=> string(19) "2016-06-20 08:00:00" ["end_date"]=> string(19) "2016-07-12 17:00:00" ["purchase_limit"]=> string(1) "0" } [3]=> object(Tribe__Tickets__Ticket_Object)#4466 (20) { ["ID"]=> int(301) ["name"]=> string(43) "1 Day Health & Safety Awareness Romford" ["description"]=> string(0) "" ["price"]=> string(3) "150" ["regular_price"]=> string(3) "150" ["on_sale"]=> bool(false) ["admin_link"]=> string(42) "http://ssstsuk.co.uk/wp-admin/&action=edit" ["frontend_link"]=> string(51) "http://ssstsuk.co.uk/1-day-health-safety-awareness/" ["provider_class"]=> string(48) "Tribe__Tickets_Plus__Commerce__WooCommerce__Main" ["provider":protected]=> NULL ["stock":protected]=> int(0) ["global_stock_mode":protected]=> string(3) "own" ["global_stock_cap":protected]=> int(0) ["qty_sold":protected]=> int(0) ["qty_pending":protected]=> int(0) ["qty_cancelled":protected]=> int(0) ["manage_stock":protected]=> bool(false) ["start_date"]=> string(19) "2016-06-20 08:00:00" ["end_date"]=> string(19) "2016-07-12 17:00:00" ["purchase_limit"]=> string(1) "0" } [4]=> object(Tribe__Tickets__Ticket_Object)#4474 (20) { ["ID"]=> int(298) ["name"]=> string(19) "2 Day SSSTS Romford" ["description"]=> string(0) "" ["price"]=> string(3) "295" ["regular_price"]=> string(3) "295" ["on_sale"]=> bool(false) ["admin_link"]=> string(42) "http://ssstsuk.co.uk/wp-admin/&action=edit" ["frontend_link"]=> string(33) "http://ssstsuk.co.uk/2-day-sssts/" ["provider_class"]=> string(48) "Tribe__Tickets_Plus__Commerce__WooCommerce__Main" ["provider":protected]=> NULL ["stock":protected]=> int(0) ["global_stock_mode":protected]=> string(3) "own" ["global_stock_cap":protected]=> int(0) ["qty_sold":protected]=> int(0) ["qty_pending":protected]=> int(0) ["qty_cancelled":protected]=> int(0) ["manage_stock":protected]=> bool(false) ["start_date"]=> string(19) "2016-06-20 09:00:00" ["end_date"]=> string(19) "2016-07-10 17:00:00" ["purchase_limit"]=> string(1) "0" } [5]=> object(Tribe__Tickets__Ticket_Object)#4650 (20) { ["ID"]=> int(237) ["name"]=> string(10) "SSSTS Test" ["description"]=> string(0) "" ["price"]=> string(4) "9.99" ["regular_price"]=> string(4) "9.99" ["on_sale"]=> bool(false) ["admin_link"]=> string(42) "http://ssstsuk.co.uk/wp-admin/&action=edit" ["frontend_link"]=> string(32) "http://ssstsuk.co.uk/sssts-test/" ["provider_class"]=> string(48) "Tribe__Tickets_Plus__Commerce__WooCommerce__Main" ["provider":protected]=> NULL ["stock":protected]=> int(0) ["global_stock_mode":protected]=> string(3) "own" ["global_stock_cap":protected]=> int(0) ["qty_sold":protected]=> int(6) ["qty_pending":protected]=> int(0) ["qty_cancelled":protected]=> int(0) ["manage_stock":protected]=> bool(false) ["start_date"]=> string(19) "2016-06-08 08:00:00" ["end_date"]=> string(19) "2016-06-17 17:00:00" ["purchase_limit"]=> string(1) "0" } [6]=> object(Tribe__Tickets__Ticket_Object)#4745 (20) { ["ID"]=> int(110) ["name"]=> string(13) "IT Training 1" ["description"]=> string(34) "Admits one person to IT Training 1" ["price"]=> string(5) "10.99" ["regular_price"]=> string(5) "10.99" ["on_sale"]=> bool(false) ["admin_link"]=> string(42) "http://ssstsuk.co.uk/wp-admin/&action=edit" ["frontend_link"]=> string(35) "http://ssstsuk.co.uk/it-training-1/" ["provider_class"]=> string(48) "Tribe__Tickets_Plus__Commerce__WooCommerce__Main" ["provider":protected]=> NULL ["stock":protected]=> int(0) ["global_stock_mode":protected]=> string(3) "own" ["global_stock_cap":protected]=> int(0) ["qty_sold":protected]=> int(2) ["qty_pending":protected]=> int(0) ["qty_cancelled":protected]=> int(0) ["manage_stock":protected]=> bool(false) ["start_date"]=> string(19) "2016-05-17 09:00:00" ["end_date"]=> string(19) "2016-06-17 17:00:00" ["purchase_limit"]=> string(1) "0" } [7]=> object(Tribe__Tickets__Ticket_Object)#4836 (20) { ["ID"]=> int(108) ["name"]=> string(21) "Health & Safety 2" ["description"]=> string(40) "Admits one person to health and safety 2" ["price"]=> string(5) "11.99" ["regular_price"]=> string(5) "11.99" ["on_sale"]=> bool(false) ["admin_link"]=> string(42) "http://ssstsuk.co.uk/wp-admin/&action=edit" ["frontend_link"]=> string(37) "http://ssstsuk.co.uk/health-safety-2/" ["provider_class"]=> string(48) "Tribe__Tickets_Plus__Commerce__WooCommerce__Main" ["provider":protected]=> NULL ["stock":protected]=> int(0) ["global_stock_mode":protected]=> string(3) "own" ["global_stock_cap":protected]=> int(0) ["qty_sold":protected]=> int(1) ["qty_pending":protected]=> int(0) ["qty_cancelled":protected]=> int(0) ["manage_stock":protected]=> bool(false) ["start_date"]=> string(19) "2016-05-17 09:00:00" ["end_date"]=> string(19) "2016-07-22 17:00:00" ["purchase_limit"]=> string(1) "0" } [8]=> object(Tribe__Tickets__Ticket_Object)#4848 (20) { ["ID"]=> int(106) ["name"]=> string(28) "Health & Safety Course 1" ["description"]=> string(49) "Admits one person to Health & Safety Course 1" ["price"]=> string(5) "11.99" ["regular_price"]=> string(5) "11.99" ["on_sale"]=> bool(false) ["admin_link"]=> string(42) "http://ssstsuk.co.uk/wp-admin/&action=edit" ["frontend_link"]=> string(44) "http://ssstsuk.co.uk/health-safety-course-1/" ["provider_class"]=> string(48) "Tribe__Tickets_Plus__Commerce__WooCommerce__Main" ["provider":protected]=> NULL ["stock":protected]=> int(0) ["global_stock_mode":protected]=> string(3) "own" ["global_stock_cap":protected]=> int(0) ["qty_sold":protected]=> int(10) ["qty_pending":protected]=> int(0) ["qty_cancelled":protected]=> int(0) ["manage_stock":protected]=> bool(false) ["start_date"]=> string(19) "2016-05-17 08:00:00" ["end_date"]=> string(19) "2016-06-10 17:00:00" ["purchase_limit"]=> string(1) "0" } }

    #1135358
    James
    Participant

    Please note that var_dump is on all the tickets outside the function so it’s showing all tickets regardless. This is because the function only works when the user confirms an order.

    #1135705
    Cliff
    Member

    If $tickets contains the WooCommerce object (like in your snippet) you should be able to get all tickets for the event using $tickets->get_tickets( $event_id )

    If there’s more than one, I’m not sure which ticket you’d want to use when picking out the title via ->name, ie:

    $first_ticket_name = '';
    $individual_tickets = $tickets->get_tickets( $event_id );
    
    if ( ! empty( $individual_tickets ) )
    $first_ticket_name = current( $individual_tickets )->name;
    
    if ( ! empty( $first_ticket_name ) )
    print $first_ticket_name;

    I hope this helps get things working for you.

    Beyond this assistance, I’m limited how much I can assist, per our Scope of Support / Terms. I hope you understand and can get things working on your own.

    If you need further coding help, you may want to ask your developer or reference our list of known customizers.

    #1135918
    James
    Participant

    No this function will be working on a single ticket, so it should only be going through a single ticket, which is the one bought by the customer. Therefore the method you’ve suggested is throwing up an internal server error.

    I’ve got the below code, could you suggest how to get it working to get the ticket title for a single ticket? (There will always only be one ticket for each event).

    $main = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
    $tickets = $main->get_tickets( $event_id );
    	
    // Get ticket title - not yet complete
    $ticket_title = current( $tickets )->name;
    • This reply was modified 9 years, 9 months ago by James.
    #1136140
    Cliff
    Member

    Can you var_dump( $tickets ); after $tickets = $main->get_tickets( $event_id ); for me?

    #1136161
    James
    Participant

    I can’t do a var_dump in the function as it comes into effect when the e-mail is sent out, since it is defining what document is attached to the e-mail. I’ve tried it and it won’t do it. Can it not be done in a similar way to the way the venue was done? (As per original posting near the comment “Get the venue name”).

    #1136281
    Cliff
    Member

    James, I’m sorry but we’re limited in helping with customizations, per our Scope of Support / Terms. I’ve tried to help point you in the right direction, but I cannot be of further help here.

    If you need some coding help, you may want to ask your developer or reference our list of known customizers.

    I do hope you get things sorted out to your satisfaction.

    #1136413
    James
    Participant

    Josh and George from your support team helped me find the venue before – maybe you could ask them to have a look please? After all this is the last bit stopping this project going live. All I need to find is the title of the ticket in question, which should be possible as the venue title was found.

    #1136720
    Cliff
    Member

    Does this help in any way?

    $first_ticket_name = '';
    $individual_tickets = $tickets->get_tickets( $event_id );
    
    if ( ! empty( $individual_tickets ) ) {
    $first_ticket_name = current( $individual_tickets )->name;
    }
    
    if ( ! empty( $first_ticket_name ) ) {
    print $first_ticket_name;
    }
Viewing 15 posts - 1 through 15 (of 18 total)
  • The topic ‘How to get the ticket title?’ is closed to new replies.