• Resolved kafar

    (@kafar)


    Hello,

    I installed the latest version of your plugin and set all.
    Now I included in functions.php the snippet below to add a checkbox for Privacy Policy but it not shows. No checkbox and no text. There is still the default info about privacy policy.

    My theme is BFastMag Pro, I read in this forum another issue similar and marker as solved, but there isn’t HOW it solved.
    Thanks.

    add_action( ‘woocommerce_review_order_before_submit’, ‘add_privacy_checkbox’, 9 );
    function add_privacy_checkbox() {
    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’ => ‘Ho letto e accetto la Privacy Policy di ProgrammareInsieme’,
    ));
    }
    add_action( ‘woocommerce_checkout_process’, ‘privacy_checkbox_error_message’ );
    function privacy_checkbox_error_message() {
    if ( ! (int) isset( $_POST[‘privacy_policy’] ) ) {
    wc_add_notice( __( ‘Accetta la nostra privacy policy per proseguire’ ), ‘error’ );
    }
    }

Viewing 7 replies - 1 through 7 (of 7 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi, @kafar!

    Use the following code:

    add_action( 'woocommerce_review_order_before_submit', 'wc_add_privacy_checkbox', 9 );
       
    function wc_add_privacy_checkbox() {
      
    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'         => 'Ho letto e accetto la Privacy Policy di ProgrammareInsieme',
    )); 
      
    }
    
    add_action( 'woocommerce_checkout_process', 'privacy_checkbox_error_message' );
      
    function privacy_checkbox_error_message() {
        if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
            wc_add_notice( __( 'Accetta la nostra privacy policy per proseguire' ), 'error' );
        }
    }

    Cheers!

    Thread Starter kafar

    (@kafar)

    Great! Thanks!

    Now, to save the privacy policy and the terms (are two checkbox) user consent in the woocmerce db and view in woocommerce wp dashboard? It’s possible?
    Thanks

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi, @kafar!

    and view in woocommerce wp dashboard?

    Where exactly? In the order as order meta or .. ?

    Cheers!

    Thread Starter kafar

    (@kafar)

    hmmm…. my question, obviously, is about the GDPR issues.
    If I need that user select two checkboxes to pay that consent I can get in my dahboard, in according with GDPR.
    “Where” is a detail. Where is possible…
    Thanks

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi, @kafar!

    There is, however, already a checkbox though, for privacy — you will only need extra checkboxes if you intend to use data for other purposes. Is that the case?

    Anyways, the following code will add an additional checkbox to the checkout, and also save the data as order meta (you’ll see it in the edit order screen of each order).

    add_action( 'woocommerce_review_order_before_submit', 'rs_wc_custom_checkout_field' );
    function rs_wc_custom_checkout_field() {
        echo '<div id="rs_wc_custom_checkout_field">';
    
        woocommerce_form_field( 'nocheck', array(
            'type'      => 'checkbox',
            'class'     => array('input-checkbox'),
            'label'     => __('Ho letto e accetto la Privacy Policy'),
        ),  WC()->checkout->get_value( 'nocheck' ) );
        echo '</div>';
    }
    
    // Save the custom checkout field in the order meta, when checkbox has been checked
    add_action( 'woocommerce_checkout_update_order_meta', 'custom_checkout_field_update_order_meta', 10, 1 );
    function custom_checkout_field_update_order_meta( $order_id ) {
    
        if ( ! empty( $_POST['nocheck'] ) )
            update_post_meta( $order_id, 'nocheck', $_POST['nocheck'] );
    }
    
    // Display the custom field result on the order edit page (backend) when checkbox has been checked
    add_action( 'woocommerce_admin_order_data_after_billing_address', 'display_custom_field_on_order_edit_pages', 10, 1 );
    function display_custom_field_on_order_edit_pages( $order ){
        $nocheck = get_post_meta( $order->get_id(), 'nocheck', true );
        if( $nocheck == 1 )
            echo '<p><strong>Extra privacy policy: </strong> <span style="color:red;">The user has agreed to the policy</span></p>';
    	elseif( $nocheck == 0 )
    		echo '<p><strong>Extra privacy policy: </strong> <span style="color:red;">The user has not agreed to the policy</span></p>';
    }

    Feel free to change it to suit your needs

    Cheers!

    Thread Starter kafar

    (@kafar)

    Thanks!

    This code above is about the privacy policy extra checkbox, but if I would like to save and see in order data the Terms and Conditions checkbox user consent done?
    Thanks again.

    Hi @kafar,

    For this it is probably best to reach out to your theme to make sure the code you placed in continues to work after the theme updates, and they can assist with further tweaking. If you have other questions please open a new thread and let us know!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Privacy Policy checkbutton’ is closed to new replies.