Created
November 20, 2020 11:37
-
-
Save yanknudtskov/97923e7a71830e3b1a6002f5bfb73ca3 to your computer and use it in GitHub Desktop.
Add a WooCommerce Checkbox at Checkout to accept privacy policy.
This file contains 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 privacy policy tick box at checkout | |
*/ | |
add_action( 'woocommerce_review_order_before_submit', 'yanco_add_checkout_privacy_policy', 9 ); | |
function yanco_add_checkout_privacy_policy() { | |
woocommerce_form_field( 'privacy_policy', array( | |
'type' => 'checkbox', | |
'class' => array('form-row privacy'), | |
'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'), | |
'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'), | |
'required' => true, | |
'label' => __('I\'ve read and I accept your', 'yanco_child_theme') . '<a href="'.get_privacy_policy_url().'" target="_blank">' . __('Privacy Policy', 'yanco_child_theme') . '</a>', | |
)); | |
} | |
add_action( 'woocommerce_checkout_process', 'yanco_not_approved_privacy' ); | |
function yanco_not_approved_privacy() { | |
if ( ! (int) isset( $_POST['privacy_policy'] ) ) { | |
wc_add_notice( __( 'You must accept our Privacy Policy.', 'yanco_child_theme' ), 'error' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment