$end_dt;
} catch ( \Exception ) {
// Keep $has_ended = false.
}
}
echo '
';
if ( $product_id && ! $has_ended ) {
$this->render_capacity_bar( $post_id );
$this->render_buy_button( $post_id, $product_id );
} elseif ( $has_ended ) {
echo '
' . esc_html__( 'This event has ended.', 'eb4tec' ) . '
';
}
if ( $eb_url ) {
echo '
' .
esc_html__( 'View on Eventbrite', 'eb4tec' ) . ' ↗
';
}
echo '
';
}
private function render_capacity_bar( int $post_id ): void {
$total = (int) get_post_meta( $post_id, '_eb4tec_capacity', true );
$available = $this->ticket_manager->get_available_capacity( $post_id );
if ( $total <= 0 ) {
return;
}
$sold = max( 0, $total - $available );
$percent = (int) round( ( $sold / $total ) * 100 );
echo '';
printf(
'
',
$sold,
$total,
$percent
);
if ( $available > 0 ) {
echo '
' . esc_html( sprintf(
/* translators: 1: available spots, 2: total */
_n( '%1$d of %2$d spot remaining', '%1$d of %2$d spots remaining', $available, 'eb4tec' ),
$available,
$total
) ) . '
';
} else {
echo '
' . esc_html__( 'Sold out', 'eb4tec' ) . '
';
}
echo '
';
}
private function render_buy_button( int $post_id, int $product_id ): void {
$available = $this->ticket_manager->get_available_capacity( $post_id );
$button_html = '';
if ( $available > 0 ) {
$product_url = get_permalink( $product_id );
$button_html = sprintf(
'