Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jessijean/85431d7a99ab9be0d540ffce9284bd40 to your computer and use it in GitHub Desktop.
Save jessijean/85431d7a99ab9be0d540ffce9284bd40 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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment