Jump to content

Recommended Posts

I'm using WordPress and Tribe's Event Calendar and Event ticket plus plugins. Their website is http://theeventscalendar.co.uk.

 

I've been using their forums but it's taking a while to sort this out, so though someone on here might be able to help. 

 

I've got an array that I need to echo out part of. Inside each key (0, 1, 2, 3 and so on) there are numerous parts like ["ID"], ["name"] and so on. I want to echo out the ["name"] part of the key. I have a var dump for 10 keys in the array, each of which have their own ["name"] set.

 

In the situation I'm using it, it will always have just 1 in the array, so I can target the first key in the array. Any ideas please on how to echo the ["name"] part? I have left a var dump of the array below.

array(10) { [0]=> object(Tribe__Tickets__Ticket_Object)#4474 (20) { ["ID"]=> int(405) ["name"]=> string(16) "2 day sssts kent" ["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(38) "http://ssstsuk.co.uk/2-day-sssts-kent/" ["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-07-07 08:00:00" ["end_date"]=> string(19) "2016-07-30 17:00:00" ["purchase_limit"]=> string(1) "0" } [1]=> object(Tribe__Tickets__Ticket_Object)#4494 (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(13) ["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" } [2]=> object(Tribe__Tickets__Ticket_Object)#4687 (20) { ["ID"]=> int(306) ["name"]=> string(46) "1 Day Health & Safety Awareness Chelmsford" ["description"]=> string(0) "" ["price"]=> string(2) "95" ["regular_price"]=> string(2) "95" ["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" } [3]=> object(Tribe__Tickets__Ticket_Object)#4662 (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" } [4]=> object(Tribe__Tickets__Ticket_Object)#4475 (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(1) ["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" } [5]=> object(Tribe__Tickets__Ticket_Object)#4705 (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(1) ["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" } [6]=> object(Tribe__Tickets__Ticket_Object)#4719 (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" } [7]=> object(Tribe__Tickets__Ticket_Object)#4803 (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" } [8]=> object(Tribe__Tickets__Ticket_Object)#4894 (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" } [9]=> object(Tribe__Tickets__Ticket_Object)#4906 (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" } }
Link to comment
https://forums.phpfreaks.com/topic/301451-echo-named-part-of-array/
Share on other sites

If you only have a single item in the array, why make it an array?

 

Anyway, it tells you that the array contains objects, so try:

 

$whatYouWantIs = $yourArray[0]->name;

you can also use a foreach to extract all the names:

 

foreach($yourArray as $k=>$v){
  $whatYouWantIs[] = $v->name;
}
$thirdName = $whatYouWantIs[2];

I've hit a real wall here. I've got your code working ok outside the required function. This means that it goes through all of the same elements.

 

However the function uses the event ID of the required item. Therefore it's just one event, so there should be just one name to check. The name of the event I'm testing contains "SSSTS" in the title, so below is my code. (by the way this is a function in my functions.php in WordPress.

function attach_doc_to_email ( $attachments , $event_id, $object ) {
// This function attaches a word doc to the order confirm e-mail based on an if statement

	// get the tickets
	$main = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
	$tickets = $main->get_tickets( $event_id );
	
	// Get ticket title - not yet complete
	foreach($tickets as $k=>$v){

		$theresult[] = $v->name;

	}

	$ticket_title = $theresult[0];
	
		
	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 the wrong result is always coming up. The way I can test this is by submitting an order each time and see if the correct attachment has been sent. The wrong attachment is always attached.

 

However the code works outside the function like below...

$main = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
	$tickets = $main->get_tickets( $event_id );
	
	foreach($tickets as $k=>$v){
		$whatYouWantIs[] = $v->name;
	}
	$name = $whatYouWantIs[0];
	
	if (strpos($name, 'sssts') !== false) {
		
		echo "yes $name";
		
	}else{
		
		echo "no";
	}

Which is very odd. Of course I need it working inside the function. Any ideas? Much appreciated.

What hook are you using to run your attach_doc_to_email() function? Are you sure it's actually being called and The Event Calendar isn't returning the default event instead of the one you're trying to grab? Try throwing in a

wp_die('This is attach_doc_to_email() calling!');

right after the function declaration. At least you'll be able to tell that the function is being called at all and can continue to troubleshoot from there.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.