Support

Home Forums Event Espresso Premium Automatic Discount Code Not Being Shown During Checkout

Automatic Discount Code Not Being Shown During Checkout

Posted: August 12, 2024 at 4:09 pm

Viewing 2 reply threads


Jonathan Patton

August 12, 2024 at 4:09 pm

We have it configured to automatically apply a discount code depending on the location they select during signup, and the discount IS being applied when you finalize the transaction, but the discount is not being displayed on the Checkout Page.


Tony

  • Support Staff

August 12, 2024 at 6:23 pm

Hi there,

We have it configured to automatically apply a discount code depending on the location they select during signup

This isn’t something EE supports out of the box, so may I ask how you are doing this? I’m assuming some custom code?

I’ll need some more details on this to see if I can help further here.

Can you link me to an event I can register onto to view this?


Jonathan Patton

August 19, 2024 at 1:49 pm

Here is what we’re using:

<?php
add_action( 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', 'jm_promo', 10 );
function jm_promo() {
if ( ! defined( 'EE_MER_PATH' ) ) {
$checkout = EE_Registry::instance()->SSN->checkout();

$do_discount = false;
$schools = array(
'School Name'=>'School Code'
);

if ( $checkout instanceof EE_Checkout ) {
$spco_obj = $checkout->reg_steps["attendee_information"];

if ($spco_obj != NULL) {

$spco_registrations = $spco_obj->checkout->transaction->registrations($spco_obj->checkout->reg_cache_where_params, TRUE);
if( !empty ( $spco_registrations ) ) {
foreach ( $spco_registrations as $registration ) {
if ( $registration instanceof EE_Registration ) {

// get the answer to the custom CC optin question
$answers = $registration->answers();

if ( !empty ( $answers ) ) {
foreach ( $answers as $answer ) {
if ( $answer instanceof EE_Answer ) {
$question = $answer->question();
$question_answers[ $question->ID() ] = $answer->pretty_value();
}
}
}
$optin = $question_answers[22];

if ( $schools[$optin] ) {
$do_discount = true;
$discount_code = $schools[$optin];
}
}
}
}
}

$transaction = $checkout->transaction;

if ( $transaction instanceof EE_Transaction ) {
foreach ( $transaction->registrations() as $registration ) {
if ( $registration instanceof EE_Registration ) {
remove_action( 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', array( 'EED_Promotions', 'add_promotions_form_inputs' ));

if ($do_discount === true) {
$cart = EE_Registry::instance()->SSN->cart();

if ($cart instanceof EE_Cart) {
// and make sure the model cache is

$cart->get_grand_total()->get_model()->refresh_entity_map_with(
$cart->get_grand_total()->ID(),
$cart->get_grand_total()
);

$tmp_promotion = new EED_Promotions;

$promotion = $tmp_promotion -> get_promotion_details_from_request($discount_code);

if ($promotion instanceof EE_Promotion) {
// determine if the promotion can be applied to an item in the current cart
$applicable_items = $tmp_promotion ->get_applicable_items($promotion, $cart, false, true);

if (! empty($applicable_items)) {
$verify_no_existing_promotion = true;

foreach ($applicable_items as $applicable_item) {
if (jm_verify_no_existing_promotion_line_items($applicable_item, $promotion) === false) {
$verify_no_existing_promotion = false;
}
}

if ($verify_no_existing_promotion === true) {
if ($tmp_promotion->generate_promotion_line_items($promotion, $applicable_items, $tmp_promotion->config()->affects_tax())) {
// ensure cart totals have been recalculated and saved
$cart->get_grand_total()->recalculate_total_including_taxes();
$cart->get_grand_total()->save_this_and_descendants();
$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
$registration_processor->update_registration_final_prices($cart->get_grand_total()->transaction());
$cart->save_cart(false);
$return_data = $tmp_promotion->_get_payment_info($cart);
//EED_Single_Page_Checkout::update_checkout();
}
}
}
}
}
}
}
}
}
}
}
}

Here is an event:
https://www.aimhightestprep.com/events/seminar-for-sept-2024-act-test-starts-8-1-24/?

A Valid Selection would be to Choose the Fremont School with the “Fremont” code.

Viewing 2 reply threads

The support post ‘Automatic Discount Code Not Being Shown During Checkout’ 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