do_action( 'learndash-course-payment-buttons-after', int $course_id, int $user_id )
Fires after the course payment button.
Description #
Parameters #
- $course_id
-
(int) Course ID.
- $user_id
-
(int) User ID.
Source #
Examples #
Note: Extended code example below not guaranteed, you may need to consult with a developer
<?php /** * Example usage for learndash-course-payment-buttons-after action. */ add_action( 'learndash-course-payment-buttons-after', function( $course_id = 0, $user_id ) { // We really only need this for Courses with 'Buy Now' (paynow) price type. This is because // when using PayPal (or Stripe) there will be a user created. $course_price_type = learndash_get_setting( $course_id, 'course_price_type' ); // New in WordPress 4.9.6. if ( function_exists( 'get_privacy_policy_url' ) ) { $privacy_policy_url = get_privacy_policy_url(); } else { $privacy_policy_url = ''; } if ( ( 'paynow' === $course_price_type ) && ( ! empty( $privacy_policy_url ) ) ) { // Check if the user is not logged in. If the user is already authenticated it // is assumed they has already consented to how data is used. if ( ! is_user_logged_in() ) { ?> <p class="join-form-consent-container" style="display:none;"><input type="checkbox" class="join-form-consent-checkbox" />I agree with the <a target="_blank" href="<?php echo $privacy_policy_url; ?>">terms and conditions</a>.</p> <?php add_action( 'wp_footer', function() { ?> <style> .learndash_checkout_buttons input.btn-join:disabled { color: #ccc !important; } </style> <script> var learndash_consent_callback = function() { // Vanilla JS. var consent_container = document.querySelector(".join-form-consent-container"); var consent_checkbox = document.querySelector(".join-form-consent-container input.join-form-consent-checkbox"); var join_button = document.querySelector(".learndash_checkout_buttons input.btn-join"); if ( ( join_button ) && ( consent_container ) && ( consent_checkbox ) ) { // Disable the main 'Take this Course' button join_button.setAttribute( 'disabled', true ); // Then show our consent block containing the checkbox consent_container.style.display = "block"; // When the consent checkbox is checked we re-enable the course submit consent_checkbox.addEventListener( 'change', function() { if ( this.checked ) { // Checkbox is checked. join_button.removeAttribute( 'disabled' ); } else { // Checkbox is not checked. join_button.setAttribute( 'disabled', true ); } }); } // Alternate jQuery version /* var consent_container = jQuery(".join-form-consent-container"); var consent_checkbox = jQuery(".join-form-consent-container input.join-form-consent-checkbox"); var join_button = jQuery(".learndash_checkout_buttons input.btn-join"); if ( ( join_button ) && ( consent_container ) && ( consent_checkbox ) ) { // Disable the main 'Take this Course' button join_button.attr('disabled', true ); // Then show our consent block containing the checkbox consent_container.show(); // When the consent checkbox is checked we re-enable the course submit consent_checkbox.change( function() { if( jQuery(this).is(':checked' ) ) { // Checkbox is checked.. join_button.attr('disabled', false ); } else { // Checkbox is not checked.. join_button.attr('disabled', true ); } }); } */ }; // Vanilla JS for jQuery .ready() function. Got to be a better way. if ( document.readyState === "complete" || ( document.readyState !== "loading" && !document.documentElement.doScroll ) ) { learndash_consent_callback(); } else { document.addEventListener("DOMContentLoaded", learndash_consent_callback); } // Alternate using jQuery //jQuery(document).ready( learndash_consent_callback); </script> <?php } ); } } }, 10, 2 );
Changelog #
Version | Description |
---|---|
2.5.8 | Introduced. |