Tribe__Tickets__REST__V1__Post_Repository::get_ticket_cost( int $ticket_id, bool $get_details = false )
Returns a ticket cost or details.
Contents
Parameters
- $ticket_id
-
(int) (Required) The ticket ID.
- $get_details
-
(bool) (Optional) Whether to get just the ticket cost (
false) or the details too ('true').Default value: false
Return
(string|array|false) The ticket formatted cost if $get_details is false, the ticket cost details otherwise; false on failure.
Source
File: src/Tribe/REST/V1/Post_Repository.php
public function get_ticket_cost( $ticket_id, $get_details = false ) {
$ticket = $this->get_ticket_object( $ticket_id );
if ( $ticket instanceof WP_Error ) {
return false;
}
/** @var Tribe__Tickets__Commerce__Currency $currency */
$currency = tribe( 'tickets.commerce.currency' );
$price = $ticket->price;
$provider = $ticket->provider_class;
if ( ! is_numeric( $price ) ) {
$price = 0; // free
}
$formatted_price = html_entity_decode( $currency->format_currency( $price, $ticket_id ) );
if ( ! $get_details ) {
return $formatted_price;
}
$details = array(
'currency_symbol' => html_entity_decode( $currency->get_provider_symbol( $provider, $ticket_id ) ),
'currency_position' => $currency->get_provider_symbol_position( $provider, $ticket_id ),
'values' => array( $price ),
);
return $details;
}
Changelog
| Version | Description |
|---|---|
| 4.8 | Introduced. |