Skip to content

Instantly share code, notes, and snippets.

@bryceadams
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save bryceadams/d6b853049e4b6ddc6365 to your computer and use it in GitHub Desktop.

Select an option

Save bryceadams/d6b853049e4b6ddc6365 to your computer and use it in GitHub Desktop.
WooCommerce Drip - Handle subscription / adding custom fields when order set to completed. This does not take into account the user's subscribe selection during checkout, and actually should be used instead of the subscribe checkbox.
add_action( 'woocommerce_order_status_completed', 'drip_subscribe_user_to_campaign', 20, 1 );
add_action( 'woocommerce_order_status_completed', 'drip_add_user_fields', 30, 1 );
function drip_subscribe_user_to_campaign( $order_id ) {
$WC_Drip_Settings = new WC_Drip_Settings();
$wrapper = $WC_Drip_Settings->wrapper();
$order = wc_get_order( $order_id );
$email = $order->billing_email;
$api_key = $wrapper['api_key'];
$account_id = $wrapper['account'];
$wcdrip_api = new Drip_API( $api_key );
$params = apply_filters( 'wcdrip_checkout_subscribe_params', array(
'account_id' => $account_id,
'campaign_id' => $wrapper['subscribe_campaign'],
'email' => $email,
) );
$wcdrip_api->subscribe_subscriber($params);
}
function drip_add_user_fields( $order_id ) {
$events = new WC_Drip_Events();
$events->new_order( $order_id );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment