fbpx

How can we help?

How to show Ticket Price

WP Event Manager Add ons Tutorials explains you, How to show ticket price field to the frontend.

Show ticket price at events listing

  1. Open your theme function.php file
  2. Create a function to append a new field to the events section.
  3. Add the following code for getting event ticket price:
    <?php
    
    function get_custom_event_ticket_price( $post = null ) {
        
        $post = get_post( $post );
        if ( $post->post_type !== 'event_listing' )
            return;
    
        return apply_filters( 'display_custom_event_ticket_price', $post->_event_ticket_price, $post );
    }
    
    ?>
    
  4. Add the following code for displaying event ticket price:
    <?php
    
    function display_custom_event_ticket_price( $before = '', $after = '', $echo = true, $post = null ) {
    
        $event_ticket_price = get_custom_event_ticket_price( $post );
    
        if ( strlen( $event_ticket_price ) == 0 )
            return;
            
        $event_ticket_price = esc_attr( strip_tags( $event_ticket_price ) );
    
        $event_ticket_price = $before . $event_ticket_price . $after;
    
        if ( $echo )
            echo $event_ticket_price;
        else
            return $event_ticket_price;
    }
    
    ?>
    
  5. Open your theme content-event_listing.php file and echo event ticket price.
    <?php printf( __( 'Ticket Price: %s', 'wp-event-manager' ), get_custom_event_ticket_price() ); ?>
    

Fields added using the above code will be show to the event ticket price automatically. There is two layout available box layout and line layout so add your above code where you want to show ticket price or you can add in both layout.

Was this article helpful?
How can we improve this article?
Quick Links