Forked from ipokkel/terms-of-service-as-a-link-only.php
Last active
November 11, 2021 15:02
-
-
Save MaryOJob/3ee6a16fec1d17c99d656435e1cfb62f to your computer and use it in GitHub Desktop.
Create a a text link to a media file (PDF) for a Terms & Conditions checkbox on checkout. #pmpro #pdf
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 // do not copy this line please | |
/** | |
* This recipe creates a Terms & Conditions checkbox on checkout | |
* with a link to the checkout page instead of displaying | |
* the Terms & Conditions page content on the page. | |
* | |
* This recipe requires that "Require Terms of Service on signups?" | |
* setting in Membershps > Settings > Advanced settings | |
* under "Checkout Settings" is set to "No". | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
// Declare function if it does not already exist. | |
if ( ! function_exists( 'my_pmprorh_init_require_tos_link' ) ) { | |
function my_pmprorh_init_require_tos_link() { | |
// Check if Register Helper is active | |
if ( ! function_exists( 'pmprorh_add_registration_field' ) ) { | |
return; | |
} | |
// Check that display TOS Setting | |
if ( ! empty( pmpro_getOption( 'tospage' ) ) ) { | |
return; | |
} | |
/** | |
* Get the link to the Terms & Conditions. | |
* | |
* To link to an existing page on your site, instead of a media file, | |
* you may replace this line: | |
* | |
* $tos_link = wp_get_attachment_url( 73 ); // Set your media file ID here. | |
* | |
* with this | |
* | |
* $tos_link = get_permalink( 73 ); // Set Terms & Conditions post ID here. | |
*/ | |
$tos_link = wp_get_attachment_url( 73 ); // Set your media file ID here. | |
// Create label that displays a link to the Terms & Conditions. | |
$label = ' I agree to the <a href="' . $tos_link . '" target="_blank" id="my-pmprorh-require-tos-link" class="my-pmprorh-require-tos-link">Terms & Conditions</a>.'; | |
// Create fields array. | |
$fields = array(); | |
// Terms & Conditions Checkbox field. | |
$fields[] = new PMProRH_Field( | |
'pmpro_tos_checked', | |
'checkbox', | |
array( | |
'label' => $label, | |
'required' => true, // make field required | |
'memberslistcsv' => true, // include in memberslist csv | |
'profile' => false, // do not display on user profile page | |
) | |
); | |
foreach ( $fields as $field ) { | |
pmprorh_add_registration_field( 'before_submit_button', $field ); | |
} | |
} | |
} | |
// Add action | |
if ( ! has_action( 'init', 'my_pmprorh_init_require_tos_link' ) ) { | |
add_action( 'init', 'my_pmprorh_init_require_tos_link' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment