Support

Home Forums Event Espresso Premium Apply amount to cart if a ticket is in the cart

Apply amount to cart if a ticket is in the cart

Posted: January 2, 2019 at 6:44 pm


CameronGilroyNNSW

January 2, 2019 at 6:44 pm

Hi,

We’re needing to add an extra amount to the cart if a specific type of ticket is in the cart.

There are two ways I can see this being able to happen: Using a coupon code or getting the cart total and adding the amount.
1. automatically add a coupon code if a specified ticket is in the cart
2. Check if a ticket is in the cart and if it is change the total price

I think option one is the best option – since it’s using the most existing code the part I’m having trouble getting working is checking if a ticket is in the cart. I haven’t found it in the documentation and was wondering if you can provides some pointers.

Thanks


CameronGilroyNNSW

January 3, 2019 at 3:32 pm

Hi,

We are needing to have add an amount if a ticket is selected, here’s an example: If either ticket type one or two is added to the cart (any quantity/combination) we need to add an extra $50.

What’s the best way to do this?

Thanks,

Cameron Gilroy


CameronGilroyNNSW

January 3, 2019 at 8:08 pm

Hi,

We are needing to have add an amount if a ticket is selected, here’s an example: If either ticket type one or two is added to the cart (any quantity/combination) we need to add an extra $50. What’s the best way to do this?

Thanks,

Cameron Gilroy

PS I’m not sure if it’s been posted – I can’t see it anywhere in the forums.


Tony

  • Support Staff

January 4, 2019 at 11:29 am

Hi there,

1. automatically add a coupon code if a specified ticket is in the cart

Currently, promotions cannot be surcharges so I’m not sure how this would work? Unless your adding your own promotion type?

2. Check if a ticket is in the cart and if it is change the total price

How are you going to change the price within the cart? Adding a line item?

Whilst checking for a ticket is the first thing you’re going to need to do (in multiple locations), if you don’t have the above worked out with some kind of plan you’re going to struggle.

So are you adding your own promotion to the promotion system to accommodate #1 and have you stepped through to see how EE builds out the transaction line items so that you can add your own to discount the total (which you’ll likely need to do regardless of the method you use)?


CameronGilroyNNSW

January 4, 2019 at 12:53 pm

Hi Tony,

I was thinking of using this code from GitHub (https://github.com/eventespresso/ee-code-snippet-library/blob/master/checkout/bc_ee_apply_transaction_surcharge.php) but I’m not sure on the best way to change it from looping through form fields to checking what kind of tickets are in the basket.

Thanks,

Cameron Gilroy


Tony

  • Support Staff

January 4, 2019 at 1:10 pm

That code applies really late, its after the user has added the tickets to their cart and also possibly visited the cart first, then added attendee information and stepped through to the payment options, only then would that snippet show a surcharge, is that not too late?

I would have thought you’d need to hook into the cart itself and the ajax request made to add/remove tickets to and from the cart to run the code as the tickets are added so you know when/if the ticket in question is added/removed.

It also seems similar to the likes of prechecked cart items that add additional fees onto the checkout process (which are frowned up and depending on your location may not actually be legal) as your showing one price at the beginning of the checkout then seemingly randomly (to the user) adding on a surcharge based on the ticket.


CameronGilroyNNSW

January 4, 2019 at 3:55 pm

Thanks for the reply Tony, the extra cost is clearly outlined.
Are there any example snippets in the GitHub repo that would be a good place to start interacting with the Ajax calls?? I’m happy to code it, but I’m hoping to find some thing I can use as a base.

If I’m checking the ticket is added and if it is then add another ticket for the amount that’s needed.

  • This reply was modified 5 months ago by  Josh.


Tony

  • Support Staff

January 7, 2019 at 3:53 pm

Are there any example snippets in the GitHub repo that would be a good place to start interacting with the Ajax calls??

I checked and couldn’t find any that would help with this, the place would recommend looking is in the Multi-Event Registration add-on itself.

There are some examples of adding surcharges to the checkout process in our snippet library here:

https://github.com/eventespresso/ee-code-snippet-library/tree/master/checkout

But you’ve already linked to one of those so I’m assuming you’ve already checked those.

I’m happy to code it, but I’m hoping to find some thing I can use as a base.

I don’t know any anyone that has done this/some similar before so I don’t think you’ll find anything similar to use as a base.

Pulling the tickets is actually the easiest part of the above, if you have the EE_Checkout object from the cart, you have an EE_Transaction object and if you have an EE_Transaction object you can do:

$registrations = $transaction->registrations();

Now you have an array of EE_Registrations linked to an EE_Ticket so you can pull/compare the names/ID/whatever for that ticket easily from there.

Heres an example of pulling the registrations from the current checkout and looping over them:

https://gist.github.com/Pebblo/f4561461339c59411a849f93c91912a9

Your will be slightly different as you’ll use the ticket from a registration but the way in which you can pull them is the same.

The support post ‘Apply amount to cart if a ticket is in the cart’ 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.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Tony 5 months, 1 week ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!