Support » Plugin: Event Tickets and Registration » event cost customization

  • Resolved rossfabio

    (@rossfabio)


    good day, i have an issue with the event cost by The Event Calendar plugin.

    When TEC plugin is used by itself i can manually insert the event cost.

    When alongside the TEC plugin i add the Event Tickets plugin, the displayed event cost field “changes” and gets the values from both the custom field in the editor and from the ticket costs too.

    Because of this, if i have an event whose full cost is 50, and sell a “reservation ticket” for 20, it will show a range 20-50 instead of just 50. Same goes for family tickets, if the event cost is 50, and i sell an individual ticket for 50 and a family ticket for 100, it will show 50-100, but i want to show only 50.

    I want to be able to display only the value i put manually in the custom field, is that possible?

    I am able to tweak the code a bit, but this plugin is too complicated to do it on my own

    Many thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Juan Aldasoro

    (@juanfra)

    Hi @rossfabio,

    Thank you for reaching out to us, I hope you’re doing well.

    You are right, when Event Tickets is installed along with The Events Calendar and if there are different ticket prices it’ll display the price range.

    What you can do is have a custom field on your own and then use the filter to put that value. The filter you’ll need to use is tribe_get_cost For example:

    add_filter( 'tribe_get_cost', 'tec_my_custom_get_cost', 10, 3 );
    
    function tec_my_custom_get_cost( $cost, $post_id, $with_currency_symbol ) {
    	$my_custom_cost = get_post_meta( $post_id, '_my_custom_cost', true );
    
    	return $my_custom_cost;
    }
    

    Please be sure that you use the right custom meta. Let me know how it goes.

    Best,
    Juan.

    Thread Starter rossfabio

    (@rossfabio)

    Thank you so much Juan, you are the man! Solved in 2 minutes thanks to you, worked great!

    I made only one change by removing the _ :

    
    add_filter( 'tribe_get_cost', 'tec_my_custom_get_cost', 10, 3 );
    
    function tec_my_custom_get_cost( $cost, $post_id, $with_currency_symbol ) {
    	$my_custom_cost = get_post_meta( $post_id, 'my_custom_cost', true );
    
    	return $my_custom_cost;
    }

    and custom field “my_custom_cost”

    thanks again!

    • This reply was modified 8 months, 2 weeks ago by rossfabio.
    Thread Starter rossfabio

    (@rossfabio)

    Sorry to bother again Juan, is there a way to do the same with the price description? This way i can just have both the cost and the cost description in the same area of the editor, so that my colleagues have it easier to fill in

    Plugin Contributor Juan Aldasoro

    (@juanfra)

    Hi @rossfabio,

    Thanks for the follow-up, I’m happy to be of help ⭐

    Are you using the blocks editor to fill in the price description now? Or where is that you’re adding that? And where do you want to change it in the front-end? In the event page directly?

    Best,
    Juan.

    Thread Starter rossfabio

    (@rossfabio)

    Hi Juan, sorry for the late reply and you’re right i should have specified a bit more what i needed to do.

    Currently yes, i was adding the price description through block editor, although i would prefer to switch to classic editor because the other people working on the backend are used to that.

    i played around a bit by modifying this file like so: the-events-calendar/src/views/blocks/event-price.php

    <?php if ( $post->my_custom_description ) : ?>
    		<span class="tribe-block__event-price__description"><?php echo esc_html( $post->my_custom_description );?></span>
    	<?php endif ?>

    which works great if i first set a price description from blocks editor and then i fill in the custom field in the classic editor, but if i skip the first step then nothing shows up, is there a way to work around that? maybe i should remove the if condition?

    again, thank you so much for the help!

    Plugin Contributor Juan Aldasoro

    (@juanfra)

    Hi @rossfabio,

    Thanks for the follow-up.

    Right, you can also follow the same logic of retrieving the meta on that template that you modified if you want to use the value from the custom field.

    Instead of having the check for $post->my_custom_description, you can have this in that template:

    
    <?php
    $my_custom_description = get_post_meta( $post_id, 'my_custom_description', true );
    
    if ( ! empty( $my_custom_description ) ) : ?>
    <span class="tribe-block__event-price__description"><?php echo esc_html( $my_custom_description );?></span>
    }
    <?php endif; ?>
    

    I’d highly encourage you not to modify the template directly on the plugin folder, but to move that to your theme overrides. Because if not, when the plugin is updated your plugin file (modified) will be overwritten. You can learn more about overrides here: https://theeventscalendar.com/knowledgebase/k/customizing-template-files-2/

    If you’re happy with the product and the support received I’d encourage you to share your experience with the rest of the community.

    Have a fantastic day,
    Juan.

    Thread Starter rossfabio

    (@rossfabio)

    thanks again juan, unfortunately this time i couldn’t get your code to work, but it brought me to the right path.

    modifying the template of the cost block wasn’t working for me (it only works if you create the event from the block editor, but that’s not my case), so i proceeded by modifying directly the single event template.

    i found something in the wordpress get post meta reference page and stylized it a bit accordingly. I inserted it into wp-content/themes/[my-theme]/tribe-events/single-event.php as suggested and it works fine

    i removed the if condition in the end, it wasn’t working for some reason and i anyways thought that if there is no text in the custom field to begin with, it’s not gonna show anything anyways.

    <?php $meta_print_value=get_post_meta(get_the_ID(),'my_custom_description',true); ?>
    <span class="tribe-block__event-price__description customcostdesc"><i><?php echo($meta_print_value); ?></i></span>
    
    <style>.customcostdesc {order: 5;}</style>

    Thanks again for all the help, you’ve been precious! I’ll leave a review right now 🙂

    Plugin Contributor Juan Aldasoro

    (@juanfra)

    That’s fantastic news.

    Thanks so much and have an awesome day,
    Juan.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘event cost customization’ is closed to new replies.