Support

Home Forums Event Espresso Premium IF customer chooses check option on checkout then changes to CC price broken

IF customer chooses check option on checkout then changes to CC price broken

Posted: May 16, 2018 at 3:24 pm


Bob Randklev

May 16, 2018 at 3:24 pm

I know this is “old school” but client has an option for each class to pay by check or credit card. Customers get a $10 discount for paying by check.

So if you go to check out and choose check… then after you submit your info/registration and on the final checkout page change your mind and choose credit card… the price doesn’t change so customers get the “check” price on credit card check out.

So customer has to call clients for $10 charge.

We’ve cleared Cloudflare cache and have our exceptions setup per the attached image.

Any ideas, suggestions?

Cloudflare exceptions


Josh

  • Support Staff

May 16, 2018 at 3:37 pm

I don’t think this is a caching issue, it’s more that Event Espresso doesn’t have a way to enforce that type of discount if it’s tied to a specific payment type.

May I ask how is the discount given in the first place? Are they selecting a ticket option or inputing a promo code at checkout? I’m not aware of an option within the payment methods that gives a discount if a specific type of payment is selected at checkout. Maybe that’s something that was custom developed for your website?


Bob Randklev

May 16, 2018 at 3:40 pm

They set two pricing options in the event for the customer to choose like:

$350 Payment by check
$360 payment by CC

So you choose check and then the next screen is your registration info.

Next screen is checkout and you can change your payment type to CC and the price is still $350.

It’s only people who change their mind, switch payment options after registration and the price doesn’t change.


Tony

  • Support Staff

May 17, 2018 at 4:19 am

They set two pricing options in the event for the customer to choose like:

$350 Payment by check
$360 payment by CC

Ok, so that’s 2 different ticket options within the event and EE has no way to know which payment method should be used for either, it just knows which payment methods are available for the event itself (not the tickets within that event).

There’s no way to change the ticket selection based on the payment method selected but what you can do tell EE to only show a check payment method if the ticket name contains the string ‘check’, you can do that using this example:

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

Add that to a custom functions plugin on your site and if the user selects a ticket that is named ‘Payment by check’ EE will only show a check payment method, otherwise it will show all payment methods.


Bob Randklev

May 17, 2018 at 5:30 am

Ok that’s working better but can we hide the other payment options IF they choose check.

We don’t want them choosing check, then paying by credit card.
Only Display Check Option


Tony

  • Support Staff

May 17, 2018 at 6:21 am

That’s exactly what the function should do. If the ticket name has ‘check’ in the name it should only show the check payment method.

You said it worked better with the function but what is it doing on your site to make it better? As it looks like it’s not doing anything from the above.


Bob Randklev

May 17, 2018 at 6:24 am

Sorry I never should have said that, I was confusing something else with this.

Here’s our complete functions.php. We’ve added a number of items over the years so maybe you can see something that is conflicting?

<?php

function ee_change_ticket_messaging_registration( $translated, $original, $domain ) {

    $strings = array(       
		'Available Tickets' => 'Choose Payment Option',
        ' / ticket' => ' / class',
		'Ticket Details' => 'Class Details',
		'Ticket Sale Dates' => 'Class Dates', 
        'Please note that a maximum number of %d tickets can be purchased for this event per order.' => 'Please note that a maximum number of %d registrations can be purchased for this event per order.',
        'The dates when this ticket is available for purchase.' => 'The dates when this class registration is available for purchase.',
		'This ticket allows access to the following event dates and times. "Remaining" shows the number of this ticket type left:' => 'This class registration allows access to the following event dates and times. "Remaining" shows the number of this registration type left:',
        'This Ticket<br/>Sold' => 'This Class<br/>Sold',
        'This Ticket<br/>Left' => 'This Class<br/>Left',
        'Total Tickets<br/>Sold' => 'Total Classes<br/>Sold',
    );

    if ( isset( $strings[$original] ) ) {
        $translations = get_translations_for_domain( $domain );
        $translated = $translations->translate( $strings[$original] );
    }
 
    return $translated;
}
 
add_filter( 'gettext', 'ee_change_ticket_messaging_registration', 10, 3 );

// Code to display EE3 custom meta
function display_custom_meta_in_ee4( $atts ){
    global $post;
    extract( shortcode_atts( array( 'type' => '', 'name' => '' ), $atts ) );
    $post_meta = get_post_meta( $post->ID, $name, TRUE );
    return $post_meta;
}
add_shortcode( 'EE_META', 'display_custom_meta_in_ee4' );
/**
 * The purpose of this snippet is to filter the event archive (and event taxonomy archive) pages so that they exclude events
 * that have tickets no longer on sale.
 *
 *  NOTE: The query for the ticket expiry time is correct at time of posting, but at some point in the future there will be a
 *  change to how date queries are done with Event Espresso and this snippet will be out of date then.  Watch for blog posts
 *  about datetime changes.
 *
 * To Implement this code, add it to the bottom of your themes functions.php file, or add it to a site specific plugin.
 *
 */
function ee_view_details_button() {
 return 'Click Here for Class Details & Registration';
}

add_filter ('FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', 'ee_view_details_button');
/**** change default to mc visa****/
function my_ee_change_add_default_ticket() {
  wp_add_inline_script( 
    'ticket_selector',
    'jQuery( document ).ready(function($) {
      $(".ee-ticket-creditdebit-card")
      .find("input.ticket-selector-tbl-qty-slct")
      .prop("checked", true);
    } );'
  );
}
add_action( 'wp_enqueue_scripts', 'my_ee_change_add_default_ticket', 11 );
//***Relevassi search form shortcode [searchform] ****/
add_shortcode('searchform', 'rlv_search_form'); 
function rlv_search_form() {
    $url = get_site_url();
    $form = <<<EOH
<form role="search" method="get" id="searchform" class="searchform" action="$url">
<label class="screen-reader-text" for="s">Search for:</label>
<input type="text" value="" name="s" id="s" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
EOH;
    return $form;
}
//*** Change name to Upcoming Classes - Sept 2017 ***//
add_action(
'FHEE__archive_espresso_events_template__upcoming_events_h1',
function(){return 'Upcoming Classes';}
);
//*** May 17 2018 *** after choosing check only display check on checkout ***//
function tw_ee_only_check_payment_method_based_on_ticket_name($payment_methods, $transaction, $scope) {
    //Double check we have a transaction object.
    if ( $transaction instanceof EE_Transaction) {

        //Initialize an array used to hold the ticket names.
        $ticket_names = array();

        //Loop over all registrations and add the ticket name for each reg to the ticket_names array.
        foreach( $transaction->registrations() as $registration ) {
            $ticket_names[] = $registration->ticket()->name();
        }

        //Loop over ticket_names, if any of them have 'check' in the name then pull a check payment method and return only that.
        foreach($ticket_names as $ticket_name){
            if (strpos($ticket_name, 'check') !== false) {
                $check_payment_method = EEM_Payment_Method::instance()->get_one_of_type( 'Check' );
                if( $check_payment_method instanceof EE_Payment_Method) {
                    $payment_methods = array();
                    $payment_methods[] = $check_payment_method;
                    break;
                }
            }
        }
    }
    return $payment_methods;
}
add_filter('FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', 'tw_ee_only_check_payment_method_based_on_ticket_name', 20, 3 );


Tony

  • Support Staff

May 17, 2018 at 7:05 am

Ah. I see the problem.

strpos() is case sensative and is looking for ‘check’.

To cover both change strpos to stripos, so it’s:

if (stripos($ticket_name, 'check') !== false) {


Bob Randklev

May 17, 2018 at 3:49 pm

That did it! Thanks!

Although is was very slow the first test it worked!


Tony

  • Support Staff

May 18, 2018 at 1:54 am

The above shouldn’t really slow down the request all that much, if it’s a check ticket it does query the database to pull a check payment method but it shouldn’t slow down the site all that much at all really.

Have you retried since that initial test?


Bob Randklev

May 18, 2018 at 5:36 am

The client has tested and they are ok with it so we will monitor and advise if there are any issues.

Thanks again for the help

The support post ‘IF customer chooses check option on checkout then changes to CC price broken’ 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  Bob Randklev 5 months ago ago

Topic Tags

Notifications

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