Add event title to WooCommerce order item title

Home Forums Ticket Products Event Tickets Plus Add event title to WooCommerce order item title

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1568634
    Josh Kern
    Participant

    I’d like to add the event title to ticket order items. I’m currently using the following function, but it’s only outputting ” – Upcoming Events”, not the actual event title.

    function woocommerce_order_item_name_event_title( $title, $item ) {
    		$event = tribe_events_get_ticket_event( $item['product_id'] );
    
    		if ( $event !== false ) {
    			$title .= sprintf( ' - <a href="%1$s">%2$s</a>', get_permalink( $event ), tribe_get_events_title( $event ) );
    		}
    
    	return $title;
    }
    add_filter( 'woocommerce_order_item_name', 'woocommerce_order_item_name_event_title', 100, 2 );

    If I try get_the_title, I only get the current page title, like “Order received” or “Order #…” if I’m on the view order page, so it’s not getting the event title based on the event id.

    Any help would be appreciated.

    #1569429
    Cliff
    Member

    Hi, Josh. I’m unsure if this existing snippet will also apply for the situation you’re wanting, but you might give it a shot:

    https://gist.github.com/cliffordp/c012f2945a22867a3af2c2878e06fffd

    Please reference https://theeventscalendar.com/knowledgebase/implementing-custom-code-snippets/ for how to implement custom code snippets.

    Of course, we always recommend restorable database and file backups as well as performing modifications first on a staging site before modifying anything on your live/production site — particularly for this snippet since it will change Products’ visibility settings.

    Please let me know how this goes for you.

    #1569444
    Josh Kern
    Participant

    Seems like this isn’t applicable to my situation. Please see attached screenshot. I’m trying to add the event name to the product name using the woocommerce_order_item_name hook.

    #1569587
    Cliff
    Member

    There’s an action and then a filter in that snippet I shared.

    With the action not in place, just the filter, this is what I see in my testing:

    Therefore, it appears to accomplish what you’re wanting.

    If you don’t agree, please specify why this wouldn’t work for you.

    #1569715
    Josh Kern
    Participant

    I don’t think you shared the right snippet. I found the solution I was looking for on this thread: https://theeventscalendar.com/support/forums/topic/duplicate-ticket-emails/

    /**
       * Add event title to order line item.
       */
      add_filter( 'woocommerce_order_item_name', 'sq_woocommerce_order_item_name', 10, 2 );
      function sq_woocommerce_order_item_name( $name, $item ) {
     
        $event = tribe_events_get_ticket_event( $item['product_id'] );
        if ( $event ) {
          $link = get_permalink( $event->ID );
          $event_date = tribe_get_start_date( $event->ID, $display_time = true, 'M j \a\t g:ia' );
          $name = $name . ' for <a href="' . $link . '">' . $event->post_title . '</a> - ' . $event_date;
        }
        return $name;
      }
    #1571108
    Cliff
    Member

    I’m glad you got what you were looking for. Note that get_permalink() could be replaced with tribe_get_event_link()

    Please let me know if you have any follow-up questions on this topic.

    #1571550
    webseo
    Participant

    would love to add it too in our cart. we have hundreds of repeating events (courses) each month and the name and dates of events are important in the cart.
    Where should I add this code snippet?

    #1571565
    webseo
    Participant

    I was able to create a “functionality plugin” and this code is wodnerful for adding th “event” name in Order receipt.
    Ho to add Vent name in cart as well???

    #1572056
    Cliff
    Member

    Again, I’ll point you to the gist snippet I previously shared at https://theeventscalendar.com/support/forums/topic/add-event-title-to-woocommerce-order-item-title/#post-1569429

    And, again, I’ll note the gist snippet includes 2 functions, one leveraging an action (you said you don’t want this functionality) and one leveraging a filter (the functionality you probably want): https://theeventscalendar.com/support/forums/topic/add-event-title-to-woocommerce-order-item-title/#post-1569587

    Please let me know how this goes for you.

    #1587703
    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 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Add event title to WooCommerce order item title’ is closed to new replies.