Support

Home Forums Event Espresso Premium Add to cart template not being read

Add to cart template not being read

Posted: February 1, 2021 at 2:22 am


Edumusik

February 1, 2021 at 2:22 am

I’ve added the following filter but the cart_results template is not being read from my child theme (which is active). Have I done this correctly?

add_filter(
    'FHEE__EEH_Template__display_template__template_path',
    function($template_path) {
        if ( $template_path === EE_MER_PATH . 'templates' . DS . 'event_cart.template.php') {
            $template_path = get_stylesheet_directory() . '/event_cart.template.php';
        }
		if ( $template_path === EE_MER_PATH . 'templates' . DS . 'cart_results_modal_dialog.template.php') {
            $template_path = get_stylesheet_directory() . '/cart_results_modal_dialog.template.php';
        }
        return $template_path;
    }
);


Tony

  • Support Staff

February 1, 2021 at 8:08 am

Hi there,

I see you’ve marked this thread resolved now, may I ask what the issue was?

I’ve just tested the above and it worked fine for me, I placed the code in a custom functions plugin rather than functions.php.

Just a quick side note on another option for this, you can use basename() to return the template filename from the path given, then you are just comparing template names rather than pull paths all the time. I have an example of doing this here:

https://gist.github.com/Pebblo/4703f274437ac01b00ef093caa8646f5

What you have is fine, just the above can be a little easier to follow when you start overriding multiple templates.


Edumusik

February 1, 2021 at 9:01 am

I forgot to activate the snippet!

Thanks for the basename() tip.


Tony

  • Support Staff

February 1, 2021 at 9:04 am

Ahh, been there, easily done 🙂

Thanks for the basename() tip.

You’re most welcome.

The support post ‘Add to cart template not being read’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso