You are currently viewing ActiveCampaign Last Order Details

ActiveCampaign Last Order Details

I have a B2B client, who wants to remind customers to place an order if they have not ordered in the last 35 days.

Since orders do not vary much, the goal was to send the customer the details of the last order 35 days after the purchase so they could easily re-order.

This client uses the WooCommerce Deep Data Integration, and ActiveCampaign stores the order details in the CRM. In an ideal world, we should be able to simply insert a tag in the email to display the details of the last order. Included in the email should be an introduction text explaining that it has been five weeks since their last order, plus a call to action to refresh inventory levels.

Sadly, this is not possible. The full order, while stored in ActiveCampaign, is not retrievable for purposes of inserting into an email. Using personalization tags, you can insert any of the elements below but you are unable to insert all the products purchased. If the customer purchased five (5) products in the last order, only the last product in the order would be available to insert into the email.

ActiveCampaign eCommerce Personalization Tag Names

  • Contact’s total revenue
  • Contact’s total # of orders
  • Total # of products ordered
  • Price of last order
  • Currency of last order
  • Shipping method of last order
  • Product count of last order
  • ID of last product purchased
  • Name of last product purchased
  • Category of last product purchased

For more information about ActiveCampaign’s Deep Data Personalization, please see this ActiveCampaign help page.

Being a programmer and the author of the WooCommerce ActiveCampaign plugin, I thought I could enhance the plugin and store the details of the last order in a custom text field in ActiveCampaign. After considering this idea, however, I realized that it did not make sense to limit the orders to the very last order. Furthermore, why store that information in parallel to the data already collected via the Deep Data Integration?

What is possible Without Coding?

Our goal – remind customers to purchase if they have not placed an order in the last 35 days and provide a way to see the details of their last order.

First and foremost, we need to record the date of the last order in ActiveCampaign. This can be done via an automation that ActiveCampaign published in their Marketplace called Store Last Purchase Date.

A second automation is needed to trigger the email after the number of specified days, 35 in our case. ActiveCampaign published that automation recipe in the Marketplace. It is called Reminder to Re-Purchase.

Note: Make sure you create a custom date field in ActiveCampaign before importing either of these automation recipes so that you can select the proper field when prompted.

All our customers have registered accounts in WooCommerce. So, we insert a link to the customer dashboard in the email to make it easy for each customer to view the details of recent orders. That dashboard page is located at https://{website}/my-account/orders/.

This approach satisfies the basic requirement – we notify the customer and using a link on the WooCommerce page, the customer is able to view the details of their recent orders.

WooCommerce Customer Dashboard list of recent orders

What Is Possible With A Bit Of Coding?

My client does not have a very extensive list of products and I thought it would be nice to display all the unique products the customer ever purchased with an ‘Add to Cart’ button for easy re-ordering.

We accomplished that additional requirement by adding a little piece of code from Business Bloomer to the theme’s functions.php file. You can find it at This piece of code will display the products in the same grid format used in the WooCommerce shop as shown below.

WooCommerce customer dashboard recent orders with grid of unique product purchased.

Our Final Rendition

WooCommerce customer dashboard showing list of recent orders plus table or unique products purchased perfect substitute for ActiveCampaign Last Order Details.

While the above certainly satisfied the requirements, I was not happy with the display. So, I did a little more research and found a free plugin called WC Product Table Lite that presents products in a nicely formatted table rather than the default WooCommerce grid.

WC Product Table Lite lets you create a table with only the columns you want in the order you prefer and the button text you specify. I created my table with the columns – Image (Image), Title (Name), Excerpt (Description), Price, Qty and Add to Cart button. For a list of tutorials to create your first table, go to

I then tweaked the code I found on Business Bloomer. I swapped out the original shortcode to use the newly created WC Product Table Lite shortcode and I added a <div tag to align the table under the orders table and included a title for the section.

I changed this line from –

return do_shortcode("[[products ids='$product_ids_str']]");

To the following line where ‘99999’ is the id of the WC Product Table you create.

return '<div class="woocommerce-MyAccount-content"><header class="woocommerce-Purchases-title title"><h4>Products You Have  Purchased</h4></header>'.do_shortcode("[product_table id='99999' ids='$product_ids_str']")."</div>";

Additionally, I wanted to only have this table appear on two pages “/my-account/downloads” and “/my-account/orders.” This was accomplished by inserting the following code at the very top of the function.

	global $wp;
	$url = home_url( $wp->request );
	if (substr($url,-21)=="/my-account/downloads" || substr($url,-18)=="/my-account/orders") {
	} else {

When the customer logs in to our site to view their recent orders, they are presented with a page that looks like the snapshot below. We are much more satisfied with this final result because our customers find it easier to renew inventory levels with a few clicks.

The full code that we used can be found below:

 * @snippet       Display All Products Purchased by User via Shortcode - WooCommerce
 * @how-to        Watch tutorial @
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.6.3
 * @donate $9
 * @modified      EqualServing to use WC Product Table Lite instead of WooCommerce grid
add_shortcode( 'eswcac_purchased_products', 'eswcac_products_bought_by_curr_user' );
function eswcac_products_bought_by_curr_user() {
	global $wp;
	$url = home_url( $wp->request );
	if (substr($url,-21)=="/my-account/downloads" || substr($url,-18)=="/my-account/orders") {
	} else {
    $current_user = wp_get_current_user();
    if ( 0 == $current_user->ID ) return;
    $customer_orders = get_posts( array(
        'numberposts' => -1,
        'meta_key'    => '_customer_user',
        'meta_value'  => $current_user->ID,
        'post_type'   => wc_get_order_types(),
        'post_status' => array_keys( wc_get_is_paid_statuses() ),
    ) );
    if ( ! $customer_orders ) return;
    $product_ids = array();
    foreach ( $customer_orders as $customer_order ) {
        $order = wc_get_order( $customer_order->ID );
        $items = $order->get_items();
        foreach ( $items as $item ) {
            $product_id = $item->get_product_id();
            $product_ids[] = $product_id;
    $product_ids = array_unique( $product_ids );
    $product_ids_str = implode( ",", $product_ids );
    return '<div class="woocommerce-MyAccount-content"><header class="woocommerce-Purchases-title title"><h4>Products You Have  Purchased</h4></header>'.do_shortcode("[[product_table id='5399' ids='$product_ids_str']]")."</div>";

Leave a Reply