Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created April 5, 2021 19:24
Show Gist options
  • Save ideadude/3f4739fcb84d7702b92c7bf8bd759f47 to your computer and use it in GitHub Desktop.
Save ideadude/3f4739fcb84d7702b92c7bf8bd759f47 to your computer and use it in GitHub Desktop.
Look up the label of an option for a PMPro Register Helper field.
<?php
/**
* Look up the label of an option for a Register Helper field.
* @param $field_name The name of the field (user meta key)
* @param $option_key The key of the option in the fields options array.
* @returns The label for the field or "N/A" if none found.
*/
function my_get_rh_option_label( $field_name, $option_key ) {
global $pmprorh_registration_fields;
if ( empty( $pmprorh_registration_fields ) ) {
return "N/A";
}
foreach( $pmprorh_registration_fields as $checkout_box ) {
foreach( $checkout_box as $field ) {
if( $field->name == $field_name ) {
if ( isset( $field->options[$option_key] ) ) {
return $field->options[$option_key];
} else {
return "N/A";
}
}
}
}
return "N/A";
}
// Here is an example of how to use it.
/*
function my_init_test() {
if ( !empty( $_REQUEST['test'] ) ) {
echo my_get_rh_option_label('budget', '5000to10000');
exit;
}
}
add_action( 'init', 'my_init_test', 20 );
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment