Forked from andrewlimaza/register_helper_checkbox_example.php.php
Last active
April 4, 2021 03:50
-
-
Save travislima/a82b004294e028cee8fff6a385241f6f to your computer and use it in GitHub Desktop.
Checkbox example for Register Helper PMPro
This file contains 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 | |
/** | |
* Add the following code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations | |
* In this example you will learn how to add 3 checkboxes to Paid Memberships Pro Checkout page. | |
*/ | |
function rh_fields_example_checkbox() | |
{ | |
//don't break if Register Helper is not loaded | |
if(!function_exists( 'pmprorh_add_registration_field' )) { | |
return false; | |
} | |
//define the fields | |
$fields = array(); | |
$fields[] = new PMProRH_Field( | |
'option1', // input name, will also be used as meta key | |
'checkbox', // type of field | |
array( | |
'label' => 'Option 1', | |
'profile' => 'true', | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'option2', // input name, will also be used as meta key | |
'checkbox', // type of field | |
array( | |
'label' => 'Option 2', | |
'profile' => 'true', | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'option3', // input name, will also be used as meta key | |
'checkbox', // type of field | |
array( | |
'label' => 'Option 3', | |
'profile' => 'true', | |
) | |
); | |
//add the fields into a new checkout_boxes are of the checkout page | |
foreach($fields as $field) | |
pmprorh_add_registration_field( | |
'checkout_boxes', // location on checkout page | |
$field // PMProRH_Field object | |
); | |
//that's it. see the PMPro Register Helper readme for more information and examples. | |
} | |
add_action( 'init', 'rh_fields_example_checkbox' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "How to add a checkbox-type field to your checkout page using Register Helper." at Paid Memberships Pro here: https://www.paidmembershipspro.com/how-to-add-a-checkbox-type-field-to-your-checkout-page-using-register-helper/