1. Home
  2. Knowledge Base
  3. WooCommerce Wholesale Lead Capture
  4. Account
  5. How to send user information to Zapier on approval

How to send user information to Zapier on approval

If you want to push newly approved wholesale customers into a mailing list or CRM automatically, you can send their details to Zapier with a webhook. This guide shows you how to send a customer’s name and email to Zapier when you approve their account, and how to do the same when you reject a lead.

This is an advanced guide. You need working knowledge of PHP and how webhooks work.

Before you start

Zapier can connect to most email marketing platforms, so it works well as the link between Wholesale Lead Capture and your mailing list. WordPress sends the data to Zapier with a simple webhook POST request. Zapier then passes it on to the app you choose.

Send customer details to Zapier when you approve a lead

  1. In Zapier, create a Zap that starts with a webhook. Zapier explains this part in Trigger Zaps from webhooks.
  2. Copy the webhook URL that Zapier gives you.
  3. In the code below, replace https://zapier.com/hooks/catch/XXXXXXXX with your webhook URL.
  4. Add the code to your child theme’s functions.php file, or to a code snippets plugin.
  5. Approve a test lead in Wholesale → Leads. Zapier receives the first name, last name and email address.
function wwlcSendWebhook( $user ) {
    $url = 'https://zapier.com/hooks/catch/XXXXXXXX'; // replace this with your Zapier provided webhook URL

    $args = array(
        'method' => 'POST',
        'body' => array(
            'first_name' => $user->user_firstname,
            'last_name' => $user->user_lastname,
            'email_address' => $user->user_email,
        )
    );

    wp_remote_post( $url, $args );
}

add_action( 'wwlc_action_after_approve_user', 'wwlcSendWebhook', 10, 1 );

The wwlc_action_after_approve_user hook runs every time a lead becomes an approved wholesale customer. That includes leads you approve yourself and leads that are approved automatically when Auto Approve New Leads is set to Automatic Approval.

If the first name or last name arrives empty, the lead has no value saved for that field. The code reads them from the user’s first_name and last_name user meta, so check the user’s profile in Users.

Hooks for approving and rejecting leads

Wholesale Lead Capture has a before hook and an after hook for each action. Each hook passes you the WP_User object of the lead. For more hooks, see How to customise Wholesale Suite with hooks and filters.

HookWhen it runs
wwlc_action_before_approve_userWhen you approve a lead, before the lead gets the wholesale role and the approval email is sent.
wwlc_action_after_approve_userAfter the lead is approved and the approval email is sent.
wwlc_action_before_reject_userWhen you reject a lead, before the rejection email is sent.
wwlc_action_after_reject_userAfter the lead is rejected and the rejection email is sent.

A lead that is already rejected does not trigger the reject hooks a second time.

Send customer details to Zapier when you reject a lead

To send the details of rejected leads to Zapier, use the reject hook in the same way. Use a separate Zapier webhook URL, so Zapier can tell approved and rejected leads apart.

function wwlcSendRejectedWebhook( $user ) {
    $url = 'https://zapier.com/hooks/catch/YYYYYYYY'; // replace this with your Zapier provided webhook URL

    $args = array(
        'method' => 'POST',
        'body' => array(
            'first_name' => $user->user_firstname,
            'last_name' => $user->user_lastname,
            'email_address' => $user->user_email,
        )
    );

    wp_remote_post( $url, $args );
}

add_action( 'wwlc_action_after_reject_user', 'wwlcSendRejectedWebhook', 10, 1 );

If Auto Remove User After Rejection is turned on, the account is already deleted when wwlc_action_after_reject_user runs. The lead’s email address is still available, but user_firstname and user_lastname come back empty, because WordPress has already deleted the user’s profile data. If you use this option and need the name, hook the example to wwlc_action_before_reject_user instead. To check or change this option, go to Wholesale → Settings → Wholesale Lead Capture → General. You can also read how rejection works in How to approve and manage leads from the Wholesale Leads dashboard.

Need help?

If you have a question or run into any issues, we’re here to help.

Was this article helpful?

Related Articles

Complete Your Purchase