Last active
April 13, 2021 18:10
-
-
Save strangerstudios/8a6bc0d2aecf015153f6 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"); |
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
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
Any suggestion on how to fix it? regards