Skip to content

Instantly share code, notes, and snippets.

@neps-in
Last active May 29, 2019 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neps-in/3cb74bd688fcb06a732f2dcc176dbf32 to your computer and use it in GitHub Desktop.
Save neps-in/3cb74bd688fcb06a732f2dcc176dbf32 to your computer and use it in GitHub Desktop.
PHP Snippet: Add Privacy Policy Acceptance Checkbox @ WooCommerce Checkout
/**
* @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