Privacy Poliy Checkbox For Wordpress Comments And Woocommerce Reviews

by admin
0 comment

In order to have a privacy policy compliant comment function on Wordpress in the EU, a number of things must be taken into account. Above all, the user's consent is required to process user data. Such an opt-in checkbox can be implemented with the following code in the functions.php file of the WP theme used:

// Fügt die Funktion dem Standard WP Kommentar sowie dem Woocommerce Review Formular hinzu
function add_privacy_field_on_comment_form() {
   $req  = get_option( 'require_name_email' );
	$aria_req = ( $req ? " aria-required='true'" : '' );
        echo '<div class="comment-form-datenschutz"><input id="datenschutz" class="my-class" name="datenschutz" type="checkbox"' . $aria_req />' .
	'<label class="my-class" for="datenschutz">' . __( 'Mit der Nutzung dieses Formulars erklären Sie sich mit der Speicherung und Verarbeitung Ihrer Daten durch diese Website einverstanden. Des weiteren geben Sie uns die Einwilligung zur Veröffentlichung Ihres Kommentars und akzeptieren unsere <a target="_blank" href="https://www.tino-designs.com/en/datenschutz/">Datenschutzerklärung.</a>' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label></div>';
    }
    add_action( 'comment_form_logged_in_after', 'add_privacy_field_on_comment_form' );
    add_action( 'comment_form_after_fields', 'add_privacy_field_on_comment_form' );


//Prüft ob die Checkbock für den Datenschutz ausgewählt wurde 
add_filter( 'preprocess_comment', 'webshaped_verify_comment_meta_data' );
function webshaped_verify_comment_meta_data( $commentdata ) {
	// Wenn die Checkbox leer ist und ein Gastnutzer schreiben möchte...
	if ( empty( $_POST['datenschutz'] ) ) {
		// ... zeige folgenden Fehlertext an
		wp_die( __( '<strong>FEHLER</strong>: Die Datenschutzbox wurde nicht akzeptiert.<br><br><a href="javascript:history.back()">« Zurück</a>' ) );
	}
	return $commentdata;
}

You may also like

Write a comment

*

* By using this form you agree to the storage and processing of your data by this website.