Last active
May 29, 2019 17:08
-
-
Save neps-in/3cb74bd688fcb06a732f2dcc176dbf32 to your computer and use it in GitHub Desktop.
PHP Snippet: Add Privacy Policy Acceptance Checkbox @ WooCommerce Checkout
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
/** | |
* @snippet Add privacy policy tick box at checkout | |
* @how-to Watch tutorial @ https://businessbloomer.com/?p=19055 | |
* @author Rodolfo Melogli | |
* @compatible WooCommerce 3.6.3 | |
* @donate $9 https://businessbloomer.com/bloomer-armada/ | |
*/ | |
// Add this code where ? | |
// You can place PHP snippets at the bottom of your child theme functions.php file (before "?> | |
add_action( 'woocommerce_review_order_before_submit', 'bbloomer_add_checkout_privacy_policy', 9 ); | |
function bbloomer_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 accept the <a href="/privacy-policy">Privacy Policy</a>', | |
)); | |
} | |
// Show notice if customer does not tick | |
add_action( 'woocommerce_checkout_process', 'bbloomer_not_approved_privacy' ); | |
function bbloomer_not_approved_privacy() { | |
if ( ! (int) isset( $_POST['privacy_policy'] ) ) { | |
wc_add_notice( __( 'Please acknowledge the Privacy Policy' ), 'error' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment