Add Custom text to Price in Upcoming Events List

Home Forums Calendar Products Events Calendar PRO Add Custom text to Price in Upcoming Events List

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #1056393
    Aindreas
    Participant

    Hello,

    Im designing a website for a charity which hosts several events. Some of these events are by donation. I need to be able to have the word ‘Donation’ where the price is displayed. It can be next to the price.

    I have played around with the php file for the upcoming events list, and have altered the way it looks and displays information (partly thanks to the great support here), but all I would be able to do there is change all of the events listed to display ‘Donation’, which is not what I need.

    If possible, is there a way to incorporate one of the Custom Fields sections to display ‘Donation’ next to the price if selected?
    If so, could you point me in the right direction of where to look and how to incorporate it into the upcoming events widget?
    Any help would be greatly appreciated!

    Kind Regards,
    Aindreas

    #1056651
    Barry
    Member

    Hi Aindreas,

    So suppose you set up a checkbox-style additional field, giving you an option like this in the event editor:

    Showing a custom field within the event editor

    You could then add the following code to your theme’s functions.php file or indeed to a custom plugin:

    function event_list_donation_marker( $cost, $post_id ) {
    	// Only add the donation marker in list view
    	if ( ! tribe_is_list_view() ) return $cost;
    
    	$fields = tribe_get_custom_fields( $post_id );
    
    	if ( ! empty( $fields['Donation'] ) && 'Yes' === $fields['Donation'] )
    		$cost .= ' BY DONATION ';
    
    	return $cost;
    }
    
    add_filter( 'tribe_get_cost', 'event_list_donation_marker', 100, 2 );

    Does that help?

    #1056932
    Aindreas
    Participant

    Thank you for the quick response!

    I added the custom field through the events calendar settings and created the Donation section with Yes and No checkboxes. I then copied the code you posted and put it in the functions.php file.
    However, it does not seem to work, though I do really like the approach you are taking. The website works as it normally does, it isnt throwing up a PHP error.
    Im sure there must be something small that is preventing this from working, any ideas on what it may be?

    Thanks again!
    Kind Regards,
    Aindreas

    #1057514
    Barry
    Member

    Can you share your code (and let me know which file it is in) and also share a screenshot of your additional field settings?

    Please consider linking to Gist or Pastebin when sharing your code – it’s a lot easier to read there than when it is pasted directly here in the forum – and, as you cannot upload images here, please share your screenshot by hosting it on your WordPress site or some place else (and simply link to it in your next reply).

    Last but not least, though I can take a further peek at this, please do note that custom dev tasks are really something we need to leave in your hands and you should treat any code we share here for these kinds of things as a starting point/rough outline only 🙂

    Thanks!

    #1066751
    Aindreas
    Participant

    Hello,

    The code I used was a direct copy of the code you posted, which I put in my ‘funtions.php’ file in the child theme of my site.
    Here is the code I copied from my site:
    http://pastebin.com/si7FFvfr

    Here is a screenshot of the checkbox setup from the settings section from the events calendar:
    http://luisne.kuglerdesign.com/wp-content/uploads/2016/02/donation-checkbox-screenshot.jpg

    If you need any other information please ask!

    I bet it is just one small thing I am missing to get it to work though, and would be very grateful for any help you can give me!

    Thank You,
    Aindreas

    #1067005
    Barry
    Member

    Hi Aindreas,

    Both the code and the screenshot of additional field settings you shared look fine to me (and if I reverse the process and copy what you shared – it again works for me locally) – so unfortunately I’m a little unsure as to why it’s failing in your case.

    Can you point me to an event for which you set Donation to Yes? I went through the first two pages of events listed on your /events/list/ page but was unable to identify any that had Donation set to Yes (unless you’ve modified your templates to hide it, I’d expect to see this information in the grey ‘meta’ area of one of the events in question).

    Thanks!

    #1067903
    Barry
    Member

    Hi Aindreas,

    Just checking in here as some gremlins in our forum software may have caused you some problems if you tried to reply yesterday.

    How are things coming along?

    #1067997
    Aindreas
    Participant

    Hi Barry,

    I didnt post anything yesterday, but thanks for asking!

    Ive added the donation option to the events ‘W. B. Yeats – The story of his family and friends’ and ‘Silent Prayer’.

    I just got a feeling that because I created my own events list file in my child theme it might be affecting it if it is working on yours. I pasted the code at: http://pastebin.com/vtcmBCEq – the file is named ‘single-event.php’.

    Again, thank you for all your time so far!
    Kind Regards,
    Aindreas

    #1068285
    Barry
    Member

    Hmm, not seeing anything there that would obviously conflict, but unless I was looking at the wrong WB Yeats event (is there more than one?) something still doesn’t feel right.

    Ordinarily, with an additional field like the one we discussed in place, I’d expect to see something along these lines in the grey meta area:

    Selection_001

    This is notable by its absence on the WB Yeats event/any of your events, which is why I wanted to double check if you either had customizations in place or if you were certain you had supplied a value for that field.

    Ultimately … I’m sorry we’ve not been able to get you on track here, but since this is really a customization task we may need to bail out at this point and leave it in your hands – as the suggested solution does seem to work as expected on a clean test site.

    #1069623
    Aindreas
    Participant

    Well, thank you for all your time Barry! I really do appreciate it. Shame it didnt work, but I guess Ill find out why not eventually.

    Is there maybe an article you could send me a link to for working with those custom fields?

    Thanks Again!
    Kind Regards,
    Aindreas

    PS: maybe leave this ticket open and if I do find the reason its not working I will post it here

    #1069661
    Barry
    Member

    Is there maybe an article you could send me a link to for working with those custom fields?

    Sure, we’ve got this:

    theeventscalendar.com/knowledgebase/pro-additional-fields

    PS: maybe leave this ticket open and if I do find the reason its not working I will post it here

    Sounds good (though do note topics are automatically closed after two weeks by our support droid, but of course you can always create a fresh topic and post your findings there – and simply link to this one).

    #1073364
    Aindreas
    Participant

    Hello again Barry,

    I have a little question regarding this issue. I have been doing some work on it and was able to display all the metadata for the event next to the event list. However, I am having trouble singling out the correct part of the metadata I require.

    My question is this:
    Could you send me the location of the file where the metadata content for a specific event is decided?
    – I have been searching through a lot of files but I feel it is like looking for a needle in a haystack, if you could point me in the right direction I would be very grateful!

    Kind Regards,
    Aindreas

    #1073373
    Barry
    Member

    Hi Aindreas,

    In terms of which template renders the additional fields, it is the following Events Calendar PRO template:

    pro/modules/meta/additional-fields.php

    If you are asking where the list of names and values comes from, it’s from a call to tribe_get_custom_fields() made in:

    Tribe__Events__Pro__Single_Event_Meta::additional_fields()

    The above class is located in src/Tribe/Single_Event_Meta.php within the Events Calendar Pro plugin directory.

    #1083908
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Add Custom text to Price in Upcoming Events List’ is closed to new replies.