Skip to content

Instantly share code, notes, and snippets.

@ronalfy
Last active October 6, 2021 17:17
Show Gist options
  • Save ronalfy/8c6334ae4d735db5b4806ec84148f875 to your computer and use it in GitHub Desktop.
Save ronalfy/8c6334ae4d735db5b4806ec84148f875 to your computer and use it in GitHub Desktop.
Paid Memberships Pro - Add Fields to Checkout and Pass Data to Zapier
<?php
function my_pmprorh_init() {
// Don't break if Register Helper is not loaded.
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) {
return false;
}
// Define the fields.
$fields = array();
$fields[] = new PMProRH_Field(
'sms',
'text',
array(
'label' => 'SMS Number (10 digit phone number e.g., 15558965555)',
'size' => 40,
'class' => 'sms',
'profile' => true,
'required' => true,
)
);
$fields[] = new PMProRH_Field(
'goals',
'text',
array(
'label' => 'What are your current goals?',
'size' => 40,
'class' => 'goals',
'profile' => true,
'required' => true,
)
);
$fields[] = new PMProRH_Field(
'diet',
'checkbox_grouped',
array(
'label' => 'What is your current diet?',
'size' => 40,
'class' => 'diet',
'profile' => true,
'required' => true,
'options' => array(
'none' => 'No Specific Diet',
'vegan' => 'Vegan',
'vegetarian' => 'Vegetarian',
'pescatarian' => 'Pescatarian',
'keto' => 'Keto',
),
)
);
// Add the fields into a new checkout_boxes are of the checkout page.
foreach ( $fields as $field ) {
pmprorh_add_registration_field(
'checkout_boxes',
$field
);
}
// That's it. See the PMPro Register Helper readme for more information and examples.
}
add_action( 'init', 'my_pmprorh_init' );
function pmpro_add_custom_data_to_zapier( $data, $user_id, $level, $order ) {
$data['sms'] = get_user_meta( $user_id, 'sms', true );
$data['goals'] = get_user_meta( $user_id, 'goals', true );
$data['diet'] = get_user_meta( $user_id, 'diet', true );
return $data;
}
add_filter( 'pmproz_after_checkout_data', 'pmpro_add_custom_data_to_zapier', 10, 4 );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Send User Profile Fields to Zapier After Membership Checkout" at Paid Memberships Pro here: https://www.paidmembershipspro.com/send-user-fields-zapier-after-membership-checkout/

@SpencerIsTheKey
Copy link

Where should this file go?

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