Tribe__Tickets__JSON_LD__Order::hook()

Setup Google Event Data for tickets.


Source

File: src/Tribe/JSON_LD/Order.php

	public static function hook() {
		$myself = self::instance();

		add_filter( 'tribe_json_ld_event_object', array( $myself, 'add_ticket_data' ), 10, 3 );

		$event_type = class_exists( 'Tribe__Events__Main' ) ? Tribe__Events__Main::POSTTYPE : 'tribe_events';
		$post_types = (array) tribe_get_option( 'ticket-enabled-post-types', array() );

		/**
		 * Other types can have tickets as well we might need to hook into each type to add tickets if any has tickets
		 */
		$filters = array();
		foreach ( $post_types as $post_type ) {
			if ( $event_type === $post_type ) {
				continue;
			}

			/**
			 * This will allow you to change the type for the Rich Snippet, by default it will use the type Product for
			 * any Post type or Page. If this is runs in a book post type the filter becomes something like.
			 *
			 * @example tribe_events_json_ld_book_type
			 *
			 * @see http://schema.org/Product
			 *
			 * @since 4.7.1
			 *
			 * @return string
			 */
			$filters[] = strtolower( (string) apply_filters( "tribe_tickets_json_ld_{$post_type}_type", 'Product' ) );
		}

		/**
		 * Avoid duplicates calls to add_filter
		 */
		$filters = array_unique( $filters );
		foreach ( $filters as $type ) {
			add_filter( "tribe_json_ld_{$type}_object", array( $myself, 'add_ticket_data' ), 10, 3 );
		}
	}