Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created April 3, 2019 12:34
Show Gist options
  • Save andrewlimaza/d9b8d01751867f3acfa7f4109f3130c8 to your computer and use it in GitHub Desktop.
Save andrewlimaza/d9b8d01751867f3acfa7f4109f3130c8 to your computer and use it in GitHub Desktop.
Send WordPress user meta data to Zapier.
<?php
/**
* This requires version 1.3+ for WP Zapier Plugin - https://yoohooplugins.com/plugins/zapier-integration/
* You may follow this function as a guide to send user meta to Zapier, or any other data really.
* This code runs whenever a user's profile is updated.
* Add the below code to a custom plugin/Child Theme function.php
*/
function my_wp_zapier_send_meta( $array, $user, $user_id ) {
// Get the user meta - value will be "Cherie"
$spouse_name = get_user_meta( $user_id, 'spouse_name', true );
// $meta_key = get_user_meta( $user_id, 'meta_key', true );
// Add data to the array we are sending to Zapier or another service/webhook.
$array['spouse_name'] = $spouse_name;
return $array;
}
add_filter( 'wpzp_send_data_profile_update_array', 'my_wp_zapier_send_meta', 10, 3 );
@mfitzz10
Copy link

This only works when it is used in the 'Notify on Profile Update' run. Is it possible to use on the 'Notify on Register' run?

@andrewlimaza
Copy link
Author

Hey @mfitzz10, you should be able to use this hook (to run on user registration instead) - https://github.com/Yoohoo-Plugins/wp-zapier/blob/master/wp-zapier.php#L297

@mfitzz10
Copy link

Hey Andrew, thanks for the quick reply I tried using that hook (code below) but not having any luck, any ideas?
function my_wp_zapier_send_meta( $array, $user, $user_id ) { //Get the user meta $distributor_name = get_user_meta( $user_id, 'distributor_name', true ); $account_number = get_user_meta( $user_id, 'account_number', true ); $zip_code = get_user_meta( $user_id, 'zip_code', true ); // Add data to the array we are sending to Zapier or another service/webhook. $array['distributor_name'] = $distributor_name; $array['account_number'] = $account_number; $array['zip_code'] = $zip_code; return $array; } add_filter( 'wpzp_send_data_register_array', 'my_wp_zapier_send_meta', 10, 3 );

@andrewlimaza
Copy link
Author

@mfitzz10, your code looks correct to me. If you var_dump the data does it show correct? Once adding to the array I'd recommend redoing your Zapier steps (to ensure this data gets captured).

@andrewlimaza
Copy link
Author

Also, this data gets cached for an hour.

@mfitzz10
Copy link

Sorry, not really familiar with PHP, how would I use var_dump?

@andrewlimaza
Copy link
Author

Please open a support ticket on https://yoohooplugins.com/support and we'll try help you if we can or advise you further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment