Created
December 17, 2020 18:44
-
-
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.
This file contains hidden or 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 | |
// 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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