Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rickalday/6360babdcc914260e945798d73db9229 to your computer and use it in GitHub Desktop.
Save rickalday/6360babdcc914260e945798d73db9229 to your computer and use it in GitHub Desktop.
Pass custom field data to Stripe when payment is processed.
<?php
function give_stripe_custom_payment_meta( $charge_args ) {
// Sanitize the input posted data to the form.
$posted_data = give_clean( filter_input_array( INPUT_POST ) );
//Uncomment the followign line to print the $posted_data array to the error log
//error_log(print_r($posted_data, TRUE));
//Get form ID
$form_id = $posted_data['give-form-id]'];
// Edit form ID number as needed
if( $form_id=123 ) {
// Prepare metadata fields list.
$custom_meta_fields = array(
'Text Field' => ! empty( $posted_data['text_field'] ) ? $posted_data['text_field'] : 'undefined',
'Dropdown Field' => ! empty( $posted_data['dropdown_field'] ) ? $posted_data['dropdown_field'][0] : 'undefined',
'Donor Comment' => ! empty( $posted_data['give_comment'] ) ? $posted_data['give_comment'] : '',
);
$charge_args['metadata'] = array_merge( $charge_args['metadata'], $custom_meta_fields );
return $charge_args;
}
return;
}
add_filter( 'give_stripe_create_intent_args', 'give_stripe_custom_payment_meta', 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment