Support

Home Forums Event Espresso Premium Remove 2nd Click "View Event Cart" action – but keep text change

Remove 2nd Click "View Event Cart" action – but keep text change

Posted: August 4, 2017 at 10:35 am

Viewing 3 reply threads


mcgilloweek

August 4, 2017 at 10:35 am

Hello,
When a user clicks the “Add to Event Cart” button, the text changes to “View Event Cart”. They can then click the same button again to be redirected to the event cart page.

Is there a hook/filter available to disable that secondary-click action (while maintaining the change in text from the first click that indicates that they’ve registered for the event)?

I have multiple ticket selectors on one page and I’m using the mini-cart shortcode to provide links to their cart, etc. I don’t want users using the ticket selector buttons to jump ahead to checkout.

I tried using a Javascript onClick() function to disable the button after the first click. However, if an error message is displayed (Event Full, etc.), the onClick function is still triggered, so the button becomes inactive before the user can actually register.

Appreciate any other options or solutions that might exist.

Thanks!


Josh

  • Support Staff

August 7, 2017 at 12:20 pm

The wp_enqueue_scripts action hook along with the
wp_add_inline_script()
function is well suited for this type of thing. Here’s an example you can try:

https://gist.github.com/joshfeck/e253df387ddd710cb739338d20065f4a

You can add the above to a functions plugin or into your WordPress theme’s functions.php file.


mcgilloweek

August 7, 2017 at 4:48 pm

That solved it! Thank you!

Out of curiosity: is there a benefit to adding this as PHP code & hook in a functions plugin vs just adding the JQuery parts of the code directly to my page?

PS: learning about .ajaxComplete() has changed my life 🙂


Tony

  • Support Staff

August 8, 2017 at 2:14 am

There’s a couple of benefits, the code within the plugin is reusable and will automatically be output to any location on your site that outputs the button (because it is hooking into the MER scripts so when are added, so is Josh’s code).

If you decide to change something within the code it’s easier to manage in a single locaition rather than multiple template files where the script may have been called etc.

Viewing 3 reply threads

The support post ‘Remove 2nd Click "View Event Cart" action – but keep text change’ 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