Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ideadude/24b5b20f18de1d6f858c7f0d5b55619b to your computer and use it in GitHub Desktop.
Save ideadude/24b5b20f18de1d6f858c7f0d5b55619b to your computer and use it in GitHub Desktop.
Add some Register Helper field data to the order notes at checkout.
/**
* Add some Register Helper field data to the order notes at checkout.
*
* 1. Update the $fields_to_add array below with the fields to save into the order notes.
* 2. Make sure PMPro Register Helper is active, the fields you want are setup and being added to the checkout page form.
* 3. Add this code to a custom plugin.
*
* Note that some advanced field types may not store their data in a human readable format.
* You may want to update this function to handle those field types specifically or to use
* nicer labels in the notes/etc.
*/
function add_rh_fields_to_order_notes_via_pmpro_checkout_order( $order ) {
$fields_to_add = array( 'agreement' );
foreach( $fields_to_add as $field ) {
if( isset( $_REQUEST[$field]) ) {
$value = sanitize_text_field( $_REQUEST[$field] );
if( !isset( $order->notes ) ) {
$order->notes = $field . ': ' . $value . "\n";
} else {
$order->notes .= $field . ': ' . $value . "\n";
}
}
}
return $order;
}
add_filter( 'pmpro_checkout_order', 'add_rh_fields_to_order_notes_via_pmpro_checkout_order' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment