Support

Home Forums Event Espresso Premium Need Promo code only applying to primary attendee

Need Promo code only applying to primary attendee

Posted: December 18, 2013 at 12:19 pm

Viewing 5 reply threads


Chris

December 18, 2013 at 12:19 pm

I have finally gotten around to testing the suggestion linked below.
https://eventespresso.com/topic/setup-suggestion-promo-code-issue/
I have it pasted into the blank plugin and the plugin activated. I have the latest version of ee and wordpress installed. Please Help.


Chris

December 18, 2013 at 1:08 pm

Something I obviously forgot to mention was that it isn’t working. I have now tried it in a custom plugin, my funcitons.php file. Neither are working.


Sidney Harrell

December 18, 2013 at 2:13 pm

One thing you might try to find out whether the code is being run is to put in a statement like:

die('code is running');

into the function. Once you’ve determined that the code is running, then you can start doing a var_dump on the data coming in, the retrieved attendee data, etc.


Chris

December 18, 2013 at 2:30 pm

I get a white page that says code is running. So I guess code is running. How should I do the var_dump?


Sidney Harrell

December 18, 2013 at 3:37 pm

var_dump($ext_att_data_source);

that variable is the one that the function is fed when the action is executed. After the line in the function that gets the $attendee variable from the database, you could do:

var_dump($attendee);

Another strategy using the die(); function is to use it to check whether code inside a conditional is being executed. So

if ($attendee['is_primary'] != 1) {die('inside the if');

if successful, can let you narrow down your focus.


Chris

December 30, 2013 at 9:42 am

Well I grabbed a co-worker and she came up with something that seems to be working. It seems that is_primary only exists for the primary attendee. So we couldn’t check it’s value for additional attendees.

This is what she came up with.

function apply_coupon_to_primary_attendee_only ($ext_att_data_source) {
	global $wpdb;
	$attendee = $wpdb->get_results('SELECT id, is_primary, registration_id, orig_price, coupon_code FROM ' . EVENTS_ATTENDEE_TABLE . ' WHERE registration_id="' . $ext_att_data_source['registration_id'].'"', ARRAY_A);

	foreach ($attendee as $item){

		$primary = $item['is_primary'];

			if ( empty ( $primary ) ) {
				$wpdb->update(EVENTS_ATTENDEE_TABLE,
				array('final_price'=>$item['orig_price']),
				array('id'=>$item['id']),
				array('%f'),
				array('%d'));

				//echo '<p>'.$wpdb->last_query.'</p>';
			}
	}	
}


Sidney Harrell

December 30, 2013 at 3:13 pm

Sorry, there is a bug in the core file, includes/process-registration/add_attendees_to_db.php, line 572:

$ext_att_data_source['attendee_id'] = $attendee_id;

that is keeping the original code snippet from working. It should be:

$ext_att_data_source['attendee_id'] = $ext_attendee_id;

The bug is sending the attendee id for the primary attendee to the hook when it should be sending the attendee id of the additional attendee. We’ll get that patched up for the next update of EE.

Viewing 5 reply threads

The support post ‘Need Promo code only applying to primary attendee’ 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