Tribe__Tickets__Tickets_View::get_tickets_block( WP_Post|int $post, boolean $echo = true )
Gets the block template “out of context” and makes it usable for non-Block Editor views.
Contents
Parameters
- $post
-
(WP_Post|int) (Required) The post object or ID.
- $echo
-
(boolean) (Optional) Whether to echo the output or not.
Default value: true
Return
(string) The block HTML.
Source
File: src/Tribe/Tickets_View.php
public function get_tickets_block( $post ) {
if ( empty( $post ) ) {
return;
}
if ( is_numeric( $post ) ) {
$post = get_post( $post );
}
if ( empty( $post ) || ! ( $post instanceof WP_Post ) ) {
return;
}
$post_id = $post->ID;
$provider_id = Tribe__Tickets__Tickets::get_event_ticket_provider( $post_id );
$provider = call_user_func( [ $provider_id, 'get_instance' ] );
/** @var \Tribe__Tickets__Editor__Template $template */
$template = tribe( 'tickets.editor.template' );
/** @var \Tribe__Tickets__Editor__Blocks__Tickets $blocks_tickets */
$blocks_tickets = tribe( 'tickets.editor.blocks.tickets' );
$tickets = $provider->get_tickets( $post_id );
$args = [
'post_id' => $post_id,
'provider' => $provider,
'provider_id' => $provider_id,
'tickets' => $tickets,
'cart_classes' => [ 'tribe-block', 'tribe-tickets' ],
'tickets_on_sale' => $blocks_tickets->get_tickets_on_sale( $tickets ),
'has_tickets_on_sale' => tribe_events_has_tickets_on_sale( $post_id ),
'is_sale_past' => $blocks_tickets->get_is_sale_past( $tickets ),
];
// Add the rendering attributes into global context.
$template->add_template_globals( $args );
// Enqueue assets.
tribe_asset_enqueue( 'tribe-tickets-gutenberg-tickets' );
tribe_asset_enqueue( 'tribe-tickets-gutenberg-block-tickets-style' );
return $template->template( 'blocks/tickets', $args );
}
Changelog
| Version | Description |
|---|---|
| 4.12.3 | Update usage of get_event_ticket_provider(). |
| 4.11.0 | Introduced. |