Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A workaround for requiring that users fill out the RH Date field. Fails checkout if date is still the same as today's date.
<?php
// Copy from below here...
/**
* Add a "Birthday" field via Register Helper.
*/
function my_pmprorh_init() {
//don't break if Register Helper is not loaded
if(!function_exists( 'pmprorh_add_registration_field' )) {
return false;
}
$checkout_area = 'checkout_boxes';
$fields = array();
$fields[] = new PMProRH_Field(
"birthday",
"date",
array(
"label" => "Birthday",
"profile" => true,
)
);
//add the fields into a new checkout_boxes are of the checkout page
foreach($fields as $field)
pmprorh_add_registration_field(
$checkout_area, // 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', 'my_pmprorh_init' );
/*
* Throw an error if RH date field is still today's date.
*/
function my_pmpro_registration_checks_birthday( $okay )
{
global $pmpro_msg, $pmpro_msgt, $current_user;
$birthday = $_REQUEST['birthday'];
$today = strtotime(date('Y-m-d'), current_time('timestamp'));
$year = date("Y", $today);
$month = date("n", $today);
$day = date("j", $today);
if ( $birthday['y'] === $year && $birthday['m'] === $month && $birthday['d'] === $day ) {
$pmpro_msg = "Please fill out the Birthday field.";
$pmpro_msgt = "pmpro_error";
return false;
}
return $okay;
}
add_filter("pmpro_registration_checks", "my_pmpro_registration_checks_birthday");
@ipokkel

This comment has been minimized.

Copy link

@ipokkel ipokkel commented Jan 7, 2021

Additional checks for if day or year fields was left empty to prevent defaulting to epoch Jan 1, 1970 when day field was empty.
https://gist.github.com/ipokkel/829397eec71c717ef2765affb5244f41

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment