Forked from strangerstudios/my_pmprorh_depends_fields_init.php
Created
October 2, 2017 00:27
-
-
Save jessijean/85431d7a99ab9be0d540ffce9284bd40 to your computer and use it in GitHub Desktop.
Demonstration of the Register Helper "depends" field option.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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