Shortcode fro event price?
WordPress Event Management, Calendars & Registration › Forums › General Question › Shortcode fro event price?
This topic contains 11 replies, has 3 voices, and was last updated by Stephen Harris 9 years, 8 months ago.
-
AuthorPosts
-
June 29, 2015 at 9:24 am #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
June 29, 2015 at 7:51 pm #17593Hi 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
June 30, 2015 at 9:55 am #17625I 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 priceI’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)
/FrankFrank Dandenell
June 30, 2015 at 11:33 pm #17641Hi 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
July 1, 2015 at 7:51 am #17652OK, 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?
/FrankFrank Dandenell
July 1, 2015 at 9:10 am #17653The 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
July 1, 2015 at 9:13 am #17654Hi 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
July 1, 2015 at 9:23 am #17656Thanx, 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!
/FrankFrank Dandenell
July 1, 2015 at 10:08 am #17658OK 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
July 1, 2015 at 10:36 pm #17668eo_the_start()
andeo_the_end()
print the date, you wanteo_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#L118Stephen Harris
July 8, 2015 at 11:42 am #17782Just 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
July 8, 2015 at 3:54 pm #17791It’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
-
This reply was modified 9 years, 8 months ago by
-
AuthorPosts