Custom Checkbox data and product info on Woocommerce Checkout page

Viewed 9

I am trying to create a checkbox on my checkout page before the checkout button. The desired information required for the checkbox should be:

"By placing an order you will be billed $PRODUCT-PRICE for PRODUCT-NAME. This is a one-time purchase. Shipment via USPS typically takes 3-5 business days. Your credit card will be billed as thbetgard.com on your statement. By placing an order you agree to our Terms and Conditions and Privacy Policy."

I have created the following in my child theme's function.php :

    // Checkout page - checkbox
function zpd_add_checkout_privacy_policy() {
    
     $configSupportFile = '/home/web1/configsupport.php';

       if( !file_exists( $configSupportFile ) ) {
           return 'Cannot find config support file.';
       }

       require $configSupportFile;
    

    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'         => 
        'This is a one-time purchase. Shipment via USPS typically takes 3-5 business days. Your card will be charged as '.$descriptor[$domain].'. By placing your order, you agree to our <a href="/privacy-policy/" target="_blank">Privacy Policy</a> and <a href="/terms-conditions/" target="_blank">Terms of Use</a>.',
    ));
}

add_action('woocommerce_review_order_before_submit',  'zpd_add_checkout_privacy_policy', 9);

// Show notice if customer doesn't check the box (required)
function zpd_privacy_not_agreed() {
    if ( ! (int) isset( $_POST['privacy_policy'] ) ) {
        wc_add_notice( __( 'Please read and accept the <strong>privacy policy</strong> to proceed with your order.' ), 'error' );
    }
}

add_action( 'woocommerce_checkout_process', 'zpd_privacy_not_agreed' );

Is there a way to retrieve and display the cart product name as well as the product price in the checkbox?

Would be amazing if anyone can help!

0 Answers
Related