Last active
August 18, 2025 16:19
-
-
Save greenhornet79/3c6562c86fd37218b05549eb2bab2ebb to your computer and use it in GitHub Desktop.
Add a terms and conditions checkbox to the Leaky Paywall registration form.
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 | |
// add fields to registration form | |
add_action('leaky_paywall_after_password_registration_field', 'endo_custom_tos_registration_fields', 100, 2); | |
function endo_custom_tos_registration_fields($level_id, $level) | |
{ | |
// do not show on free levels | |
if ( $level['price'] == 0 ) { | |
return; | |
} | |
// adjust wording if the level is recurring | |
if ( $level['recurring'] == 'on' ) { | |
$text = 'I understand I will be automatically billed on my renewal date unless I cancel'; | |
} else { | |
$text = 'I understand this is a one-time payment that does not autorenew'; | |
} | |
?> | |
<div class="form-row"> | |
<input style="display: inline;" type="checkbox" required id="tos" name="tos"> <label for="tos" style="display: inline;"><?php echo $text; ?>, and I agree to all <a target="_blank" href="<?php echo home_url('subscription-terms'); ?>">terms and conditions</a>.</label> | |
</div> | |
<?php | |
} | |
add_filter('leaky_paywall_account_setup_validation', 'endo_validate_tos', 20, 2); | |
function endo_validate_tos($errors, $fields) | |
{ | |
if (!isset($fields['tos'])) { | |
$errors['tos'] = array( | |
'message' => __('You must agree to the terms and conditions to continue.', 'leaky-paywall'), | |
); | |
} | |
return $errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment