Get Currency Symbol

Home Forums Calendar Products Events Calendar PRO Get Currency Symbol

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1013780
    David
    Participant

    How can I get the currency symbol assigned to an event please ?

    Hoping for something like

    $currency = tribe_get_event_currency_symbol( $postId )

    Thanks

    David

    #1013868
    Nico
    Member

    Hi there David,

    Thanks for reaching out on this! Hopefully there’s an easy way of getting the currency symbol for an event:


    $currency = tribe_get_event_meta( $postId, '_EventCurrencySymbol', true );

    You can take a look into ‘wp-content/plugins/the-events-calendar/src/functions/template-tags/general.php’ there are some functions to work with cost / currency that you might find useful. Eg: tribe_format_currency at line 821.

    Please let me know if this works as expected,
    Best,
    Nico

    #1014259
    David
    Participant

    Great thanks, that worked great. I’m using it as a “spare field”. My events never have a cost, so I’m using the currency field as an ordinal value cheat. I’ve adapted the list widget to display the featured image for any event and I use whether or not the currency symbol is a ‘X’ to determine whether clicking on the featured image in the widget should link to the Event details or directly to the Event website.

    Code below if anyone is interested.

    
    <?php
    /**
     * Events Pro List Widget Template
     * This is the template for the output of the events list widget.
     * All the items are turned on and off through the widget admin.
     * There is currently no default styling, which is highly needed.
     *
     * Override this template in your own theme by creating a file at [your-theme]/tribe-events/pro/widgets/list-widget.php
     *
     * When the template is loaded, the following vars are set:
     *
     * @var string $start
     * @var string $end
     * @var string $venue
     * @var string $address
     * @var string $city
     * @var string $state
     * @var string $province
     * @var string $zip
     * @var string $country
     * @var string $phone
     * @var string $cost
     * @var array  $instance
     *
     * @package TribeEventsCalendarPro
     *
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	die( '-1' );
    }
    
    // Retrieves the posts used in the List Widget loop.
    $posts = tribe_get_list_widget_events();
    
    // The URL for this widget's "View More" link.
    $link_to_all = tribe_events_get_list_widget_view_all_link( $instance );
    
    // Check if any posts were found.
    if ( isset( $posts ) && $posts ) :?>
    
    <?php	foreach ( $posts as $post ) :
    		setup_postdata( $post );
    		do_action( 'tribe_events_widget_list_inside_before_loop' ); ?>
    
    		<!-- Event  -->
    		<div class="<?php tribe_events_event_classes() ?>">
    		<?php  
    		$currency_symbol = tribe_get_event_meta( $postId, '_EventCurrencySymbol', true ); 
    		if ($currency_symbol == 'X')
    		{
    		// use the web site we've set as the event
    		$website_url = tribe_get_event_website_url( $postId );
    		}
    		else
    		{
    		// link to the event page
    		 $website_url = esc_url( tribe_get_event_link() ); 
    		 }?>
    		 
    		<?php if ( !empty( $website_url ) ) { echo '<a href="' . $website_url . '">'; }?>
    		<div class="tribe_navigator_image">
    		<?php echo get_the_post_thumbnail( $post->ID, 'medium' );?>
    		</div>
    		<?php if ( !empty( $website_url )  AND $currency_symbol !='X') { echo '</a>'; }?>
    			<?php tribe_get_template_part( 'pro/widgets/modules/single-event', null, $instance ) ?>
    		<?php if ( !empty( $website_url )  AND $currency_symbol =='X') { echo '</a>'; }?>
    		</div><!-- .hentry .vevent -->
    
    		<?php do_action( 'tribe_events_widget_list_inside_after_loop' ) ?>
    
    	<?php endforeach ?>
    
    	<p class="tribe-events-widget-link">
    		<a href="<?php esc_attr_e( esc_url( $link_to_all ) ) ?>" rel="bookmark">
    			<?php esc_html_e( 'View More&hellip;', 'tribe-events-calendar-pro' ) ?>
    		</a>
    	</p>
    
    <?php
    // No Events were found.
    else:
    ?>
    	<p><?php //printf( __( 'ORIGINAL There are not any upcoming %s at this time.', 'tribe-events-calendar' ), strtolower( tribe_get_event_label_plural() ) ); ?></p>
    <?php
    endif;
    
    // Cleanup. Do not remove this.
    wp_reset_postdata();
    
    #1014285
    Nico
    Member

    Hey David,

    Glad I could help you out here, also thanks for sharing your hack 🙂

    Not an usual use of the currency symbol field I must say, but if it works… ¯\_(ツ)_/¯

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Best,
    Nico

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Get Currency Symbol’ is closed to new replies.