Selectively Hide the Add to Cart Link

Overview

Here’s a simple tweak that makes a lot of sense. You have an event that either isn’t taking registration or you want people to email you for inquiries instead of registering on the site. With the Multi Event Registration add-on active, you will see an Add to Cart link regardless of whether you are displaying a registration form. As discussed in another document, this is handy if you want to use the Multi Event checkout instead of the regular registration form. However, by default, you’ll still get the Add to Cart link in your Event List. In this tutorial, I’ll show you two ways to hide the Add to Cart link for different uses.

In both methods, we’ll be editing the event_list_display.php. You’ll want to refer to Customizing Your Upcoming Events Widget Using CSS and Template Files and the Template Glossary if you have any questions about how to edit the template files or what to do with them once you’ve modified them.

Method 1: Hiding the registration form also hides the Add to Cart link

The first method hides the Add to Cart link when the registration form is hidden. This is actually pretty easy. Scroll down to the bottom of event_list_display.php to this block of code:

       if ($display_reg_form == 'Y') {
            ?>

           <p id="register_link-<?php echo $event_id ?>" class="register-link-footer">
                <a class="a_register_link" id="a_register_link-<?php echo $event_id ?>" href="<?php echo $registration_url; ?>" title="<?php echo stripslashes_deep($event_name) ?>"><?php _e('Register', 'event_espresso'); ?></a>
                <?php echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; ?>
            </p>
        <?php } else { ?>
            <p id="register_link-<?php echo $event_id ?>" class="register-link-footer">
                <a class="a_register_link" id="a_register_link-<?php echo $event_id ?>" href="<?php echo $registration_url; ?>" title="<?php echo stripslashes_deep($event_name) ?>"><?php _e('View Details', 'event_espresso'); ?></a> <?php echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; ?>
            </p>
        }

This is checking if Display Registration Form is set to Yes, and if so, it displays one type of Register link. If not, it changes the ‘Register’ to ‘View Details’. In either case, it displays the cart link. We’re going to fix that last part by focusing on the second half:

        <?php } else { ?>
            <p id="register_link-<?php echo $event_id ?>" class="register-link-footer">
                <a class="a_register_link" id="a_register_link-<?php echo $event_id ?>" href="<?php echo $registration_url; ?>" title="<?php echo stripslashes_deep($event_name) ?>"><?php _e('View Details', 'event_espresso'); ?></a> <?php echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; ?>
            </p>
        <?php
        }

All we need to do here is remove the part that displays the cart link, which is this:

<?php echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; ?>

With that part pulled out the whole block looks like this:

       if ($display_reg_form == 'Y') {
            ?>

           <p id="register_link-<?php echo $event_id ?>" class="register-link-footer">
                <a class="a_register_link" id="a_register_link-<?php echo $event_id ?>" href="<?php echo $registration_url; ?>" title="<?php echo stripslashes_deep($event_name) ?>"><?php _e('Register', 'event_espresso'); ?></a>
                <?php echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; ?>
            </p>
        <?php } else { ?>
            <p id="register_link-<?php echo $event_id ?>" class="register-link-footer">
                <a class="a_register_link" id="a_register_link-<?php echo $event_id ?>" href="<?php echo $registration_url; ?>" title="<?php echo stripslashes_deep($event_name) ?>"><?php _e('View Details', 'event_espresso'); ?></a>
            </p>
        }

…which says “If Display Registration Form is set to Yes, display a ‘Register’ link along with an ‘Add to Cart’ link. Otherwise, display a ‘View Details’ link and don’t display an ‘Add to Cart’ link.”

Method 2: Hide the Add to Cart link using EE_META

That’s all fine and dandy, but what if you want to hide the registration form but you do want to display the ‘Add to Cart’ link, just not on this event (or this series of events). In this case we’re going to create a meta key, store that in a variable, then check to see if the variable matches our criteria and use that to determine whether or not to display the ‘Add to Cart’ link. Ready? Here we go:

First we need to create our meta key and value pair. This is done in the event. We can call the meta key whatever we want, so I’ll do something obvious like ‘display_cart_link’. Now we have our meta key and we can use this on any event. For this event, I don’t want to display the cart link, so my value is going to be ‘N’.

display_cart_link

Easy enough. Now let’s add that to the event_list_display.php.

First let’s declare a variable that pulls in the value of our new meta key. Above this line:

if ($display_reg_form == 'Y') {

add this:

$display_cart_link = do_shortcode('[EE_META type="event_meta" name="display_cart_link"]');

We’ve just created a variable called $display_cart_link that will pull in the EE_META value for ‘display_cart_link’ (if it exists). Now we need to check whether we want to display the cart link. Again, we’re doing this in the second half of this if/else statement:

       if ($display_reg_form == 'Y') {
            ?>

           <p id="register_link-<?php echo $event_id ?>" class="register-link-footer">
                <a class="a_register_link" id="a_register_link-<?php echo $event_id ?>" href="<?php echo $registration_url; ?>" title="<?php echo stripslashes_deep($event_name) ?>"><?php _e('Register', 'event_espresso'); ?></a>
                <?php echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; ?>
            </p>
        <?php } else { ?>
            <p id="register_link-<?php echo $event_id ?>" class="register-link-footer">
                <a class="a_register_link" id="a_register_link-<?php echo $event_id ?>" href="<?php echo $registration_url; ?>" title="<?php echo stripslashes_deep($event_name) ?>"><?php _e('View Details', 'event_espresso'); ?></a> <?php echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; ?>
            </p>
        }

In the else we’ll add this:

<?php if ($display_cart_link != 'N') { echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; } ?>

So the whole thing looks like this:

       $display_cart_link = do_shortcode('[EE_META type="event_meta" name="display_cart_link"]');
       if ($display_reg_form == 'Y') {
            ?>

           <p id="register_link-<?php echo $event_id ?>" class="register-link-footer">
                <a class="a_register_link" id="a_register_link-<?php echo $event_id ?>" href="<?php echo $registration_url; ?>" title="<?php echo stripslashes_deep($event_name) ?>"><?php _e('Register', 'event_espresso'); ?></a>
                <?php echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; ?>
            </p>
        <?php } else { ?>
            <p id="register_link-<?php echo $event_id ?>" class="register-link-footer">
                <a class="a_register_link" id="a_register_link-<?php echo $event_id ?>" href="<?php echo $registration_url; ?>" title="<?php echo stripslashes_deep($event_name) ?>"><?php _e('View Details', 'event_espresso'); ?></a> <?php if ($display_cart_link != 'N') { echo isset($cart_link) && $externalURL == '' ? $cart_link : ''; } ?>
            </p>
        }

This time we’re saying “If Display Registration Form is set to Yes, display a ‘Register’ link and the ‘Add to Cart’ link. Otherwise, display the ‘View Details’ link and check if the ‘display_cart_link meta value is set to ‘N’. If it’s not set to ‘N’, we are displaying the cart link, so do that. If not, hide the cart link.” Here’s what my event list looks like:

Event List


Need more help?

  • Browse or search for more information on this topic in our support forums. Customers with an active support license can open a support topic and get help from Event Espresso staff.
  • Have an emergency? Purchase a support token and get expedited one-on-one help!
  • Go back to documentation for Event Espresso
Event Espresso