Send attachment based on purchased ticket's location/venue

Home Forums Ticket Products Event Tickets Plus Send attachment based on purchased ticket's location/venue

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1116368
    James
    Participant

    I bought the tickets plugin and got the free calendar plugin.

    I have got the following code in the functions.php file in my theme which sends a word document with the order confirmation e-mail to the client.

    /* attach a word doc with each purchase. Need if statements though. */
    function attach_doc_to_email ( $attachments , $id, $object ) {
    	$your_doc_path = get_template_directory() . '/instructions/joining-instructions-ahs-chelmsford.docx';
    	$attachments[] = $your_doc_path;
    	return $attachments;
    }

    That works fine. But I have a set of 6 documents – three types of courses (CITB, SSSTS and other) in 2 different locations (colchester and romford). What I want is if the user chooses a CITB course in Colchester, the correct word doc is sent out. Is it possible to add in a few if statements to decide this?

    Alternatively can I have the variables for the venue and title please? (Might be able to do a string check on the title for the course type).

    #1116688
    Josh
    Participant

    Hey James,

    Thanks for reaching out to us!

    I may not be following the needed setup exactly, however it sounds like it may be best to set some type of meta (either some custom meta or a new taxonomy) for the events and set the course types on the event.

    You could then check taxonomy of the associated event for the product ID of the ticket beings sent and attach the necessary document path that way.

    Let me know if this helps.

    Thanks!

    #1116791
    Josh
    Participant

    Hey James,

    Thanks for reaching out to us!

    I may not be following the needed setup exactly, however it sounds like it may be best to set some type of meta (either some custom meta or a new taxonomy) for the events and set the course types on the event.

    You could then check taxonomy of the associated event for the product ID of the ticket beings sent and attach the necessary document path that way.

    Let me know if this helps.

    Thanks!

    #1116904
    James
    Participant

    Thanks for the reply.

    How would I go about doing this? I only started using WordPress recently, not too sure how to go about doing that. Would I need to do an override on any files? Or will it all be in the function on functions.php?

    #1118118
    James
    Participant

    Could you please give me the variables I need to use the title of the event ticket being bought? Also variables for the ID, venue and other information. or the method to get them please?

    #1118684
    George
    Participant

    Hey James,

    Josh is out of office for a bit so I just wanted to step in here. I have to bear some bad news, unfortunately, because we actually can’t dive into variable-by-variable, function-by-function assistance with custom coding at all.

    We cannot help with code modifications, custom designs, etc., so you unfortunately will have to take to the reins on making your customizations a reality.

    ⚠️ Please read this page to learn more: https://theeventscalendar.com/knowledgebase/what-support-is-provided-for-license-holders/


    Now, while what I wrote above is true and we will not be able to help with the coding process here, I did want to at least try to help a bit and offer some general advice. You ask about how to get titles and such from the tickets…

    Well, there are a number of ways to do it. Tickets are just post types, so you could get them in an array by using code like the following:

    // $event_id is the ID of the Event whose tickets you want to get info about.
    $main = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
    $tickets = $main->get_tickets( $event_id );

    Where to go from here? Well, I would recommend simply doing a var_dump() on that $tickets variable to see all of the data that it already provides. You could then use a number of WordPress and PHP functions from there on that $tickets variable to extract all sorts of additional, specific data you want.

    Next, when it comes to getting venue information, you can use all sorts of WordPress functions to get information from Venues because venues are just a post type.

    To get the actual Venue ID though, so that you CAN then use those WordPress functions to begin with, try out some code like this:


    // $event_id is the ID of the Event whose venue you want to get info about.
    $venue_id = tribe_get_venue_id( $event_id );

    Now you can do stuff like this to get post information about the Venue, like the title etc:


    $venue_info = get_post( $venue_id );


    Other Resources

    You can learn more about getting information from post types here:
    http://codex.wordpress.org
    • https://codex.wordpress.org/Function_Reference/get_post_field
    https://developer.wordpress.org/reference/functions/get_post/
    • Exploring the /src/template-tags/ folders in any Events Calendar/Event Tickets plugin for a series of handy template-tag functions that get and show specific bits of data.


    From here, to implement the features you describe, you would have to write that custom code or hire a professional developer to do it for you. We have a list of great developers here → http://m.tri.be/18k1 (and have no affiliation with any of these folks—they’re simply some well-respected names in the community that we’ve compiled to share in situations like this one).

    I hope this information helps! Best of luck with your custom coding.

    George

    #1123805
    James
    Participant

    Thanks for the reply, and sorry for being late with mine!

    I’ve tried “$venue_info = get_post( $venue_id );” but of course the title can’t be taken from just this.

    I have tried the following…

    $venue_title = get_post_title( $venue_info );

    $venue_title = tribe_get_post_title( $venue_info );

    But with no luck. The if statement runs ok BUT it returns the same result (first option, the “correct” option) each time.

    The if statement I’m running is below…

    if ($venue_info = "chelmsford") {
    	
    		$your_doc_path = get_template_directory() . '/instructions/citb-health-and-safety-awareness-course-chelmsford.docx';
    		
    	}else{
    		
    		$your_doc_path = get_template_directory() . '/instructions/citb-health-and-safety-awareness-course-colchester.docx';
    	}

    I’m guessing I’m not getting the title correctly. Can you help me in getting it right please? I bet not much more is needed to be honest!

    Thanks for your patience! 🙂

    #1124517
    Josh
    Participant

    Hey James,

    Would you mind posting a full snippet of what you’re trying to use here?

    Based on the snippets above, you wouldn’t be able to get the information from “$venue_info” because that would have a post object rather than just the venue_id.

    However, if you follow the three snippets above provided by George, you should be able to get the title by modifying his last snippet to use “get_the_title( $venue_id ); ”

    Let me know if this helps.

    Thanks!

    #1124532
    James
    Participant

    I have tried your code but it is now returning the second result in the if statement no matter what. For an event with a venue of “Chelmsford” it should send the Chelmsford document, and for a Colchester one it should send the Colchester document. My code is below. Do you know where I’m going wrong please?

    function attach_doc_to_email ( $attachments , $id, $object ) {
    	
    	$main = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance();
    	$tickets = $main->get_tickets( $event_id ); // gets the tickets
    	
    	$venue_id = tribe_get_venue_id( $event_id ); //the id of the event's venue eg Chelmsford's id
    	$venue_info = get_post( $venue_id ); 
    	$venue_title = get_the_title( $venue_id ); 
    	
    	if (strpos($venue_title, 'Chelmsford') !== false || strpos($venue_title, 'chelmsford') !== false) {
    	
    		$your_doc_path = get_template_directory() . '/instructions/citb-health-and-safety-awareness-course-chelmsford.docx';
    		
    	}else{
    		
    		$your_doc_path = get_template_directory() . '/instructions/citb-health-and-safety-awareness-course-colchester.docx';
    	}
    	
    	$attachments[] = $your_doc_path;
    	return $attachments;
    }
    #1124993
    Josh
    Participant

    Hey James,

    Thanks for adding this! It gives a better picture to help here!

    The first thing that stands out here would be that in this context, it looks like the “$event_id” variable isn’t actually set, so “$venue_id” won’t actually be returning anything either.

    When using the “attach_doc_to_email()” function, is the $id that you’re passing into it intended to be the event id? If so, try using that instead of “$event_id” in those functions.

    Let me know if this helps.

    Thanks!

    #1125000
    James
    Participant

    And with that it’s fixed! Forgot about that bit 😛

    Got to learn some way I suppose! Thanks for your help and patience!

    #1125004
    Josh
    Participant

    Hey James,

    Awesome! Happy to help. And this also the best way to learn  🙂

    I’ll go ahead and close this thread for now. If you have any further questions, please don’t hesitate to open a new one.

    Thanks!

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Send attachment based on purchased ticket's location/venue’ is closed to new replies.