Payment Method on Ticket

Home Forums Calendar Products Events Calendar PRO Payment Method on Ticket

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #1325645
    Karl Edy
    Participant

    Dear Support,

    I’d like to display the payment Method on the Tickets of the customers.

    I tried to put it in the email.php like so:
    echo '<p><strong>Payment Type:</strong> ' . $order->payment_method_title . '</p>';
    but this doesn’t work.

    any help?

    thanks!

    #1326641
    Barry
    Member

    Hi Karl,

    Thanks for posting!

    Please note however that the degree of support we can provide for custom dev tasks like this does tend to be on the limited side. If I can, though, I’d be happy to point you in the right direction.

    Within the ticket loop contained in tickets/email.php you can access $ticket[‘ticket_id’]. Using this, you can obtain the order ID:

    $order_id = get_post_meta( 
        $ticket['ticket_id'],
        Tribe__Tickets_Plus__Commerce__WooCommerce__Main::ATTENDEE_ORDER_KEY,
        true
    );

    You can then take the order ID and use the WooCommerce API to obtain information about the order (please see their docs for more detail on that process).

    Does that help at all?

    #1326688
    Karl Edy
    Participant

    Hello,

    I tried it like the code below, but it doesn’t work.
    If I confirm the ticket via WooCommerce it redirects me to an extra page where I see the ticket, but without any information about anything. (see screenshot) It neither sends the ticket per email.

    Code:

    $order_id = get_post_meta( 
        $ticket['ticket_id'],
        Tribe__Tickets_Plus__Commerce__WooCommerce__Main::ATTENDEE_ORDER_KEY,
        true
    );
    $order = wc_get_order( $order_id );
    $order_data = $order->get_data();
    $order_payment_method = $order_data['payment_method'];
    echo $order_payment_method;

    Thank you for your help!

    #1326908
    Barry
    Member

    Hi Karl,

    If I confirm the ticket via WooCommerce it redirects me to an extra page where I see the ticket

    This is really strange as, by default, this doesn’t normally happen.

    Instead, the expected behaviour is that after going through checkout the customer will ultimately see an order confirmation page – but this does not include the actual tickets as per your screenshot.

    Do you have customizations in place to achieve this? If so, might they be interfering with the normal dispatch of the ticket emails?

    #1327391
    Karl Edy
    Participant

    Hi Barry,

    At first, thank you for your help!

    I managed to get the payment method working in the ticket email, but now i get an error if i want to “Download a PDF copy of this ticket”. I have the tribe-ext-view-tickets plugin installed.

    error:

    Fatal error: Uncaught Error: Call to a member function get_data() on boolean in /home/.sites/856/site2268/web/wp-content/themes/unite/tribe-events/tickets/email.php:320 Stack trace: #0 /home/.sites/856/site2268/web/wp-content/plugins/event-tickets/src/template-tags/tickets.php(574): include() #1 /home/.sites/856/site2268/web/wp-content/plugins/event-tickets/src/Tribe/Tickets.php(1264): tribe_tickets_get_template_part(‘tickets/email’, NULL, Array, false) #2 /home/.sites/856/site2268/web/wp-content/plugins/tribe-ext-view-tickets/index.php(160): Tribe__Tickets__Tickets->generate_tickets_email_content(Array) #3 /home/.sites/856/site2268/web/wp-includes/class-wp-hook.php(298): Tribe__Extension__View_Print_Tickets->show_ticket_page(”) #4 /home/.sites/856/site2268/web/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array) #5 /home/.sites/856/site2268/web/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #6 /home/.sites/856/site2268/web/wp-settings.php(469): do_action(‘wp_loaded’) #7 /home/.sites/856/site22 in /home/.sites/856/site2268/web/wp-content/themes/unite/tribe-events/tickets/email.php on line 320

    it seems to increment the tribe_view_ticket_order by 1 if i want to download the ticket.
    as seen in the url: /?tribe_view_ticket_order=2294&tribe_pdf_ticket=true

    here is the code on line 320 in my email.php:

    312 # get payment_method
    313				//start
    314				$order_id = get_post(
    315						$ticket['order_id'],
    316					Tribe__Tickets_Plus__Commerce__WooCommerce__Main::ATTENDEE_ORDER_KEY,
    317						true
    318				);
    319				$order = wc_get_order($order_id);
    320				$order_data = $order->get_data();
    321				$order_payment_method = $order_data['payment_method'];
    322				//end

    I then echo the $order_payment_method in an if statement to get some text if it’s cash on delivery (cod):

    if (strcmp($order_payment_method,'cod')==0) {
    															echo "<p>Bitte bezahlen Sie Ihr Ticket beim Eintreffen!</p>";
    														} else {
    															echo 'Bereits bezahlt!';
    														};
    #1327695
    Barry
    Member

    Interesting problem!

    WooCommerce won’t provide the order object until after post types have been registered, which makes sense on a number of levels. If wc_get_order() is called before that point in time it will return false instead of an order object, which would account for the error you are experiencing.

    To avoid the error you could test to see if you have a valid result before trying to print the payment method, ie:

    $order = wc_get_order($order_id);
    
    if ( $order ) {
        // Code to fetch and display
        // the payment method
    }

    Of course, the payment method will be missing in those cases where the PDF is downloaded. I’m not sure how much of a problem that may or may not be for you?

    #1328652
    Karl Edy
    Participant

    Thank you, but that doesn’t suit my needs.

    Yes your solution avoids the error, but I need the paymentmethod on the ticket. Also on the PDF ticket.

    do you have another workaround for me?

    thank you in advance!

    #1328746
    Barry
    Member

    OK, how about revising that snippet (in your email template) to the following:

    $order = wc_get_order( $ticket['order_id'] );
    
    if ( $order ) {
    	$order_data           = $order->get_data();
    	$order_payment_method = $order_data['payment_method'];
    	echo $order_payment_method;
    }
    #1328795
    Karl Edy
    Participant

    Hi please delete my previous answer. this was Carmens fault.

    And no, that doesn’t solve the problem..

    #1329060
    Barry
    Member

    Your other post has been deleted 🙂

    Re the problem at hand, let’s switch from obtaining $ticket[‘order_id’] to grabbing $ticket[‘order_id_display’] instead. That certainly seems to work for me, for both the regular ticket email and for the PDFs, too.

    #1329304
    Karl Edy
    Participant

    I do not get data with $ticket[‘order_id_display’] …

    #1329411
    Barry
    Member

    Seems fine to me – are you mixing and matching WooCommerce tickets with RSVPs perhaps?

    Either way, I’m sorry to say we’re pretty much at the end of what we can do to help you here: as noted at the start, the degree of support we can offer for custom dev tasks tends to be limited so all I can hope is that the above at least gives you a starting point and you can take things forward under your own steam and iron out any further problems from there.

    Remember that, if you need more help than we can provide here (with custom development in particular) there are plenty of folks who can help:

    http://theeventscalendar.com/find-a-customizer

    Good luck with the project 🙂

    #1339807
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 13 posts - 1 through 13 (of 13 total)
  • The topic ‘Payment Method on Ticket’ is closed to new replies.