Shortcode fro event price?

This topic contains 11 replies, has 3 voices, and was last updated by  Stephen Harris 9 years, 8 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #17578

    Hi Stephen, I would like to show the event price on the event page, separate from the booking form. How can I do that, I looked for shortcode but couldn’t find any for the price.

    Best regards, Frank

    Frank Dandenell
    #17593

    Hi Frank,

    There’s no shortcode for the event price as an event can have multiple tickets, and even multiple tickets for different dates (if selling by date).

    In your case is the going to be only one ticket?

    Stephen Harris
    #17625

    I see your point. In my case I have a set of courses (appr 5) which occur at differents dates and locations during the year, but always the same price.

    What I still need to solve is how to put a list for each course
    with
    date 1, location 1 and price.
    date 2, location2 and price

    I’ve managed OK to solve this by customizing the booking form and creating separate tckets for each location and pu this in the widget area.
    But I would like to be able print out the price somehow, it’s ok if it’s only the price for the first ticket (since price are the same for all dates/locations)
    /Frank

    Frank Dandenell
    #17641

    Hi Frank,

    This snippet creates a simple list of future dates, together with the price and name of the ticket.

    The plug-in already creates lists an event’s future dates in event-meta-single-event.php so you may prefer to modify that to include price and ticket name.

    This snippet loops through future dates, extracts a ticket for that date and display its name and price:

    add_shortcode( 'my_price_list', function(){
        $event_id = get_the_ID();
        $occurrences = eo_get_the_future_occurrences_of( $event_id );
        $html = '<ul>';
        foreach( $occurrences as $occurrence_id => $occurrence ) {
    
            $tickets = eo_get_event_tickets( $event_id, $occurrence_id );
            $ticket = array_pop( $tickets );
    
            $date = eo_get_the_start( get_option('date_format'), $event_id, null, $occurrence_id );
            $name = esc_html( $ticket['name'] );
            $price = eo_format_price( $ticket['price'] );
    
            $html .= "<li>$date, $location - $price</li>";      
        }
        $html .=  '</ul>';
    
        return $html;
    });
    

    You can use the shortcode on any event: [my_price_list]

    Stephen Harris
    #17652

    OK, looks good. I tried pasting the code in shortcodes,php
    No luck I just get a 500 error when I try to load any page.

    Is it supposed to go in another file?
    /Frank

    Frank Dandenell
    #17653

    The above uses an anonymous function which requires php 5.3+ so you’ll need to change that if you’re running 5.2.

    Otherwise I don’t see why it wouldn’t work (I tested it before posting). If you’re running php5.3+ then I’d recommend checking your error logs to see what the cause was.

    Also, don’t make changes to the plugin itself as these will be lost when you update. I’d recommended using a utility plugin or failing that a (child) theme’s functions.php (see http://wp-event-organiser.com/blog/tutorial/where-should-i-put-code-from-the-tutorials/)

    Stephen Harris
    #17654

    Hi again, got it working, some of the < and > got corrupted when pasting the code.

    I also added end date, since I have 2 day events. Earlier you helped me with an if statment, which made a single day event only print out start date (end date would only be repetitive), and on a 2 day event also print out end date. I can’t figure out how to implement this code in this shortcode. Please help 😉 I tried for several hours now, but I’m starting to question my career choice…. This is your conditional statement.

    <?php  if ( eo_get_the_start( 'Ymd' ) == eo_get_the_end( 'Ymd' ) ) { ?>
             <li> <?php eo_the_start($date_format) ?></li>          
    <?php } else { ?>
             <li> <?php eo_the_start($date_format) ?> - <?php eo_the_end($date_format) ?> </li>
    <?php } ?>
    
    • This reply was modified 9 years, 8 months ago by  Stephen Harris.
    Frank Dandenell
    #17656

    Thanx, I have the code working now and it’s put in my child themes functions.php. No worries, but thanks for pointing this out – it’s sometimes tempting to alter in the core files.

    However, wrote you about adding an if statement in your code, di you see this.

    And again, the more I use thos plugin, the more I like it – great job!
    /Frank

    Frank Dandenell
    #17658

    OK Stephen, you may send me an invoice soon ,-)
    New request: Would it be hard to format the date so that a 2 day event would look like
    1-2 september 2015
    instead of
    1 september 2015 – 2 september 2015

    /Frank

    Frank Dandenell
    #17668

    eo_the_start() and eo_the_end() print the date, you want eo_get_the_*() counterparts which return it:

    <?php
    $date_format = get_option( 'date_format' );
     if ( eo_get_the_start( 'Ymd' ) == eo_get_the_end( 'Ymd' ) ) {
         $date = eo_get_the_start($date_format, $event_id, null, $occurrence_id );
    } else {
         $date = eo_get_the_start($date_format, $event_id, null, $occurrence_id); 
         $date .= ' - '; 
         $date .= eo_get_the_end($date_format, $event_id, null, $occurrence_id );
    }
    ?>
    

    Regarding formatting the date as 1-2 september 2015 – this will be much easier with 3.0.0 (currently in beta), using this funtion: eo_format_event_occurrence() : https://github.com/stephenharris/Event-Organiser/blob/develop/includes/event-organiser-utility-functions.php#L118

    Stephen Harris
    #17782

    Just looking this thread, and was interested in the last post. Is it possible to display the dates like:
    1-2 september 2015 – Or can this only be done in 3.0.0?

    Alex Steer
    #17791

    It’s possible, but 3.0.0 will have dedicated function, which given a date format will split it appropriately. Until then you’d have to handle the logic yourself. For 1-2 September 2015, you would need to insert between the two conditions above:

    }elseif ( eo_get_the_start( 'Ym' ) == eo_get_the_end( 'Ym' ) ) {
       $date = eo_get_the_start('j', $event_id, null, $occurrence_id); 
       $date .= ' - '; 
       $date .= eo_get_the_end('j F Y', $event_id, null, $occurrence_id )
    }
    
    Stephen Harris
Viewing 12 posts - 1 through 12 (of 12 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.