Last active
February 1, 2022 09:02
-
-
Save andrewlimaza/d265d2b4be137f3a12d4f838dff0b219 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( | |
'grower', // input name, will also be used as meta key | |
'checkbox', // type of field | |
array( | |
'label' => 'Grower', | |
'required' => true, | |
'profile' => true, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'irrigator', // input name, will also be used as meta key | |
'checkbox', // type of field | |
array( | |
'label' => 'Irrigator', | |
'required' => true, | |
'profile' => true, | |
) | |
); | |
$fields[] = new PMProRH_Field( | |
'retailer', // input name, will also be used as meta key | |
'checkbox', // type of field | |
array( | |
'label' => 'Retailer', | |
'required' => true, | |
'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' ); | |
@cremigerhonig for support regarding products or code snippets, please reach out to https://www.paidmembershipspro.com
Please see this article for the available "profile" attribute options which allows you to show it only on the checkout page - https://www.paidmembershipspro.com/documentation/register-helper-documentation/adding-fields/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to make sure people are not able to change checkboxes on their profile page?
if you use this code, you can visit your profile page and edit the checkbox after checkout again..... doesn´t make any sense