Home › Forums › Ticket Products › Event Tickets Plus › How to get the ticket title?
- This topic has 18 replies, 4 voices, and was last updated 9 years, 8 months ago by
James.
-
AuthorPosts
-
June 30, 2016 at 3:01 am #1133862
James
ParticipantI’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.
June 30, 2016 at 4:16 pm #1134262Cliff
MemberHi 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.
July 1, 2016 at 1:15 am #1134379James
ParticipantIt 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.
July 1, 2016 at 9:52 pm #1134713Cliff
MemberThanks 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.
July 2, 2016 at 1:20 am #1134743James
ParticipantThis 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)
July 4, 2016 at 10:39 am #1135145Cliff
MemberI 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?July 5, 2016 at 1:11 am #1135356James
ParticipantThe 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" } }July 5, 2016 at 1:21 am #1135358James
ParticipantPlease 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.
July 5, 2016 at 1:52 pm #1135705Cliff
MemberIf
$ticketscontains 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.
July 6, 2016 at 6:12 am #1135918James
ParticipantNo 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.
July 6, 2016 at 11:03 am #1136140Cliff
MemberCan you
var_dump( $tickets );after$tickets = $main->get_tickets( $event_id );for me?July 6, 2016 at 11:40 am #1136161James
ParticipantI 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”).
July 6, 2016 at 2:59 pm #1136281Cliff
MemberJames, 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.
July 7, 2016 at 12:52 am #1136413James
ParticipantJosh 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.
July 7, 2016 at 10:58 am #1136720Cliff
MemberDoes 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; } -
This reply was modified 9 years, 9 months ago by
-
AuthorPosts
- The topic ‘How to get the ticket title?’ is closed to new replies.
