WooCommerce and AWeber

I’ve recently worked with a client who has a couple of online stores powered by WooCommerce. I’ve done a little work here and there with customizing WooCommerce, but this client is my first to want AWeber lists integrated.

The good news is that many WooCommerce plugins integrate nicely with AWeber, and she’s also using Gravity Forms, which make AWeber integration even more easy. For the most part, hooking up AWeber to whatever other feature we need is as easy as installing a plugin and setting it up.

However, we have a very specific need that was not satisfied by any plugins I found: there are certain products for which we would like to send out updates. The price of these products includes free updates to new versions and access to alternative formats. So we wanted to be able to sign someone up to an AWeber list for a specific product.

The AWeber API is actually very straightforward, and their cookbook code samples are great. WooCommerce is not always as clear, but debugging any issues is typically pretty easy. The gist of my solution, which hooks into the ‘woocommerce_order_status_completed’ action, is below:

1
2
3
4
5
6
7
8
9
10
11
12
13
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach($items as $product){
    if(array_key_exists($product['id'], $product_lists)){
        $app = new THCGaweberApp();
        $list = $app->findList($name=$product_lists[$product['id']]);
        $subscriber = array(
            'email' => $order->billing_email,
            'name'  => $order->billing_first_name.' '.$order->billing_last_name
        );
        $app->addSubscriber($subscriber, $list);
    }
}

Leave a Reply