Skip to content

Instantly share code, notes, and snippets.

@dparker1005
Created December 17, 2020 18:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dparker1005/155113d46e4c2a83f41c38b0c4662193 to your computer and use it in GitHub Desktop.
Save dparker1005/155113d46e4c2a83f41c38b0c4662193 to your computer and use it in GitHub Desktop.
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
Copy link

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