Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active April 13, 2021 18:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save strangerstudios/8a6bc0d2aecf015153f6 to your computer and use it in GitHub Desktop.
Save strangerstudios/8a6bc0d2aecf015153f6 to your computer and use it in GitHub Desktop.
Demonstration of the Register Helper "depends" field option.
<?php
function my_pmprorh_depends_fields_init()
{
//don't break if Register Helper is not loaded
if(!function_exists("pmprorh_add_registration_field"))
{
return false;
}
//add a new "About Your Pets" box on checkout form
pmprorh_add_checkout_box("pets", "About Your Pet");
//define the fields
$fields = array();
$fields[] = new PMProRH_Field(
"pet",
"select",
array(
"label"=>"I have a:",
"options"=>array(
"" => "Select",
"cat"=>"Cat",
"dog"=>"Dog"
)));
$fields[] = new PMProRH_Field(
"cat_name",
"text",
array(
"depends"=>array(array('id' => "pet", 'value' => "cat")),
"label"=>"Cat's Name",
));
$fields[] = new PMProRH_Field(
"dog_name",
"text",
array(
"depends"=>array(array('id' => "pet", 'value' => "dog")),
"label"=>"Dog's Name",
));
//add the fields into a new "pets" area of the checkout page
foreach($fields as $field)
pmprorh_add_registration_field(
"pets",
$field
);
}
add_action("init", "my_pmprorh_depends_fields_init");
@nanomania82
Copy link

Hello, I can't get conditional logic to work, for example I want to make selecting when a options appear in a selector and it doesn't work for me, it doesn't work for me or pasting this code as it is, nothing appears to me, this is my code that I am making

//CAMPOS DE CLASES

$fields_for_clases = array();
$fields_for_clases[] = new PMProRH_Field(
	'Clases Particulares?',				// input name, will also be used as meta key
	'radio',							// type of field
	array(
        'buddypress' => 'Clases Particulares?',       // XProfile Field Name <-- !!!
		'label'		=> 'Clases',		// custom field label
		'class'		=> 'clases particulares?',		// custom class
	    'required'	=> true,			// make this field required
	    'levels'        => array( 2,3,4 ),   // only levels 1 and 2 should have the company field
	    
    	'options' => array(
		     'option_value' => 'Si','No',
		)
	)
);	

$fields_for_personal[] = new PMProRH_Field(
	'Experiencia',							// input name, will also be used as meta key
	'text',								// type of field
	array(
	    'buddypress' => 'Experiencia',       // XProfile Field Name <-- !!!
		'label'		=> 'Experiencia',		// custom field label
		'size'		=> 40,				// input size
		'class'		=> 'experiencia',		// custom class
		'profile'	=> true,			// show in user profile
		'required'	=> true,			// make this field required
		'levels'        => array( 2,3,4 ),   // only levels 1 and 2 should have the company field
	        "depends"=>array(array('id' => "Clases Particulares?", 'value' => "Si")),
	        "label"=>"Clases",
	)
);	

foreach($fields_for_clases as $field)
	pmprorh_add_registration_field(
		'clases',				// location on checkout page
		$field						// PMProRH_Field object
	);

Any suggestion on how to fix it? regards

@laurenhagan0306
Copy link

This recipe is included in the blog post on "Exploring Register Helper: Adding Conditional Fields to Member Profile and Checkout" at Paid Memberships Pro here: https://www.paidmembershipspro.com/exploring-register-helper-adding-conditional-fields-member-profile-checkout/

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