Support

Home Forums Event Espresso Premium Using EE Shortcodes outside of Event Espresso

Using EE Shortcodes outside of Event Espresso

Posted: June 24, 2024 at 12:26 am

Viewing 3 reply threads


pathwise

June 24, 2024 at 12:26 am

Original discussion: https://eventespresso.com/topic/using-ee-shortcodes-outside-of-ee/

Summary. Looking to include a shortcode in a GroundHogg email for “Abandoned Carts” allowed the user to continue with their registration.

Event Espresso does appear to provide transaction continuation links with [payment_url], however adding that to an email does not work out of the box.

Based on the original forum post this is what I was able to come up with, however it is throwing an error for me when delivering the email

function generate_ee_transaction_link_by_user($atts) {
    // Shortcode attributes, expecting 'user_id'
    $attributes = shortcode_atts(array(
        'user_id' => '',
    ), $atts);

    if (empty($attributes['user_id'])) {
        return 'Error: User ID not provided.';
    }

    global $wpdb;
    $reg_url_link = $wpdb->get_var($wpdb->prepare(
        "SELECT REG_code FROM {$wpdb->prefix}esp_registration WHERE ATT_ID = %d AND STS_ID = 'RIC' LIMIT 1",
        $attributes['user_id']
    ));

    if (empty($reg_url_link)) {
        return 'Error: No pending transaction found for the provided user.';
    }

    $reg_page_url = EE_Registry::instance()->CFG->core->reg_page_url();

    $url = add_query_arg(array(
        'e_reg_url_link' => $reg_url_link,
        'step'           => 'payment_options',
        'revisit'        => true,
        'clear_session'  => false,
    ), $reg_page_url);

    return esc_url($url);
}
add_shortcode('ee_pending_transaction_link_by_user', 'generate_ee_transaction_link_by_user');

Inserting the shortcode into the email with

[ee_pending_transaction_link_by_user user_id="{contact.user_id}"]

This appears to be properly generating the URL correctly to appear in the email. Example:

/registration-checkout/?uts=1713971179&e_reg_url_link=7183-6664-1-8c75&step=payment_options&revisit=1#checkout

However, after visiting that link we are seeing the following errors:


Your Registration and Transaction information could not be retrieved from the db.
EED_Single_Page_Checkout - _get_transaction_and_cart_for_previous_visit - 861


Your Registration and Transaction information could not be retrieved from the db.
EED_Single_Page_Checkout - _verify_transaction_and_get_registrations - 821


Tony

  • Support Staff

June 24, 2024 at 6:32 am

Hi there,

So the issue related to the specific error here is relatively simple, REG_code is the incorrect value to use for the link, you need REG_url_link.

So SELECT REG_url_link ... (Side note, why not use the models to pull this in without having to handle the query yourself?)

However, there are also some other issues with what you have here.

Something I should note early on is ATT_ID is NOT the WordPress user_id, based on your code I can’t say for sure if that’s how you are trying to use it but user_id implies it so just make sure that is not. ATT_ID is the EE_Contact ID, it can be related to a WP User account but it is NOT the ID of that WP User.

So then when you have this WHERE ATT_ID = %d AND STS_ID = 'RIC'

You’re looking for a registration linked to a specific EE Contact ID (ATT_ID) with a STS_ID of RIC which is short for Registration InCcomplete. A RIC Registration is one that doesn’t have an ATT_ID assigned to it, it’s an incomplete registration because it doesn’t have the attendee data. So this query will never return anything, because you’ll never have a valid ATT_ID on a RIC registration.

I think what you are looking for is an abandoned transaction, which is an EE_Transaction with a status of TAB.

So presumably you want the ‘last’ abandoned transaction link to a user?

What data do you have for that user when generating the email?


pathwise

June 24, 2024 at 7:59 am

So presumably you want the ‘last’ abandoned transaction link to a user?

That is correct, that would work for our needs.

As for what is available, I believe the entire user object should be available or something similar. I was using it in my shortcode like this with the WordPress User ID {contact.user_id}

[ee_pending_transaction_link_by_user user_id=”{contact.user_id}”]

However, yeah I guess if there is no user_id it doesn’t really make sense.

I didn’t use the EE model because I didn’t find it at the time, so I just wrote the SQL I needed, happy to update it to have better code though.


Tony

  • Support Staff

June 24, 2024 at 9:07 am

As for what is available, I believe the entire user object should be available or something similar. I was using it in my shortcode like this with the WordPress User ID {contact.user_id}

Yeah, but what is contact in that context, where is that pulling the data from?

I’ll give you some details, but what/how you use them depends on your setup.

If you are using the WP User integration add-on and users are required to log in to start a registration within EE then you can using something like:

$att_id = get_user_option('EE_Attendee_ID', get_current_user_id());

To pull in the ATT_ID related to the current user (if indeed there is one).

Then just use the Registrations models to pull in the registration linked to a transaction with a status of TAB (I hightly recommend digging into the models, it makes much more complex queries relatively simple to do. If doing anything within EE you cangeneral use the models to get the data quickly and ‘easily’), like so:


$att_id = get_user_option('EE_Attendee_ID', get_current_user_id());

if(empty($att_id) ) {
    return;
} 

$where = [
    'ATT_ID' => $att_id,
    'Transaction.STS_ID' => 'TAB'
];

$reg = EEM_Registration::instance()->get_one([
	$where,
	'order' => 'DESC'
]);

$reg will be the ‘last’ registration created for that registration where the TXN Status is currently abandoned (ordered by the REG ID desc).

This gets more complex when you don’t require login and/or don’t use the WP user integration add-on to sync the ATT_ID to the WP user, you then need to use the data you have available to try and find the correct Attendee (EE_Contact). Which is possible, but can be error prone depending on your setup.

But… the models make these queries easier than you would expect. So lets say we only have the email address, we want the same as above but all we have is an email, meaning in English we want ‘The registration linked to an abandoned transaction if its linked to an EE_Contact with the email address of {X}’

$where = [
    'Attendee.ATT_email' => 'bob@example.com',
    'Transaction.STS_ID' => 'TAB'
];
$reg = EEM_Registration::instance()->get_one([
	$where,
	'order' => 'DESC'
]);

(Note we don’t use ATT_ID anymore, we don’t have that in this example)

Done.

Narrow it down more with more attendee data like first name, last name etc.

Oh, and grabbing the REG_url_link from the EE_Registration you’ll get from above (in both of my examples) is done with:

$reg_url_link = $reg->reg_url_link();

Viewing 3 reply threads

The support post ‘Using EE Shortcodes outside of Event Espresso’ 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