Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Last active February 1, 2022 09:02
Show Gist options
  • Save andrewlimaza/d265d2b4be137f3a12d4f838dff0b219 to your computer and use it in GitHub Desktop.
Save andrewlimaza/d265d2b4be137f3a12d4f838dff0b219 to your computer and use it in GitHub Desktop.
Checkbox example for Register Helper PMPro
<?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' );
@andrewlimaza
Copy link
Author

andrewlimaza commented Feb 1, 2022

@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