Support

Home Forums Multiple Event Registration Add-on Replacing Add to Cart Link

Replacing Add to Cart Link

Posted: January 15, 2014 at 9:11 am

Viewing 10 reply threads


novaopen

January 15, 2014 at 9:11 am

I want to replace the default “Add to Cart” link with my own custom link. I have reviewed the documentation “Selectively hide the Add to Cart link”. Will this remove ALL “Add to Cart” links or just on the Event Registration page. Further, will I be able to define my own “Add to Cart” links without them being hidden, too. I was planning on using [ESPRESSO_CART_LINK event_id="311-312" direct_to_cart=1 moving_to_cart="Redirecting to cart..."] in order to add two events at once. I am setting all events to hide Registration form, too.


novaopen

January 15, 2014 at 9:54 am

OK, I have tried Method 1 from the article and it worked for me with the default Event Registration. Can I assume that I can do something similar with espresso_table.php?

Finally, can I put non-core EE files (like plugins for MER) into the uploads/espresso/templates folder, too?


novaopen

January 15, 2014 at 10:09 am

Further, to automate the setting of the first value of the event_id, I’d like to use a shortcode that calls the event_id of the current/active event. The second value is a constant. This is the code I was thinking: [ESPRESSO_CART_LINK event_id="[my nested shortcode that calls the current ID]-312" direct_to_cart=1 moving_to_cart="Redirecting to cart..."]

Is there such a shortcode. Lacking that, could I call it in the PHP. How would I structure that?


novaopen

January 15, 2014 at 1:28 pm

I took my first stab at writing my own shortcode.

<code>//Returns event_id value for the current record.
//Best used nested with other shortcodes

//[EVENT_ID]
function event_id_func( $atts ){
	&lt;?php echo $event_id ?&gt;;
}
add_shortcode(&#039;EVENT_ID&#039;, &#039;event_id_func&#039;);</code>

but it broke the rendering of the Event Registration page. Thoughts on where I went wrong?


Josh

  • Support Staff

January 15, 2014 at 7:14 pm

Hi Michael,

OK, I have tried Method 1 from the article and it worked for me with the default Event Registration. Can I assume that I can do something similar with espresso_table.php?

It’s possible, although add-to-cart links aren’t standard in the espresso_table.php, but if you add them, they can be selectively hidden.

Finally, can I put non-core EE files (like plugins for MER) into the uploads/espresso/templates folder, too?

No, only templates are checked for in that location. Any other files will be ignored. If you want to override pluggable functions or add new functions, Event Espresso will look in /wp-content/uploads/espresso/custom_functions.php for these.

Further, to automate the setting of the first value of the event_id, I’d like to use a shortcode that calls the event_id of the current/active event. The second value is a constant. This is the code I was thinking: [ESPRESSO_CART_LINK event_id=”[my nested shortcode that calls the current ID]-312″ direct_to_cart=1 moving_to_cart=”Redirecting to cart…”]
Is there such a shortcode. Lacking that, could I call it in the PHP. How would I structure that?

While there isn’t a shortcode that returns the current event’s event ID, you can use the $event_id variable. If the $event_id variable isn’t set, like in the case of espresso_table.php, something like $event->id will work.

I took my first stab at writing my own shortcode.

the php tag cannot be used inside another php tag.
$event_id isn’t defined.


novaopen

January 20, 2014 at 1:30 pm

The only problem I have had using the [ESPRESSO_CART_LINK] is the updated “View Cart” link reverts back to “Add to Cart” when you do a full page reload. This is not the case with the default “Add to Cart” link. Recommendations?


Josh

  • Support Staff

January 20, 2014 at 2:09 pm

It may help to see the code you are using within the context of where the cart link shortcode is being included. Or is this a case where the shortcode is being added directly to the page within a page editor?


novaopen

January 20, 2014 at 4:11 pm

<div class="ecl">[ESPRESSO_CART_LINK event_id="356-323-327" anchor="Add to Cart"]</div> is at the end of the Event Description.


Josh

  • Support Staff

January 20, 2014 at 7:06 pm

You can open up cart.php and change line 1072 from:

if ( $view_cart || is_array( $events_in_session ) && isset( $events_in_session[ $event_id ] )) {

to:

if ( $view_cart || is_array( $events_in_session ) && isset( $events_in_session[ $this_event_id ] )) {

Then when you click the add to cart link that’s generated by the add to cart shortcode, then reload the page, it will still say view cart.


novaopen

January 21, 2014 at 10:36 am

Awesome (and Easy). Is that now a code refinement for core as I see that the default View Cart still works? (Mine are turned off, so I tested). If so, it is cool to know that I’m helping the process along.


Josh

  • Support Staff

January 21, 2014 at 11:34 am

I’m not sure, I’ll need to check with the Dev team on the intent of that check.

Viewing 10 reply threads

The support post ‘Replacing Add to Cart Link’ 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