mardi 1 décembre 2020

How to add a custom checkbox to select all checkboxes on woocommerce checkout page to the woocommerce_review_order_before_submit?

I need to add a checkbox with the option to select all the checkboxes below it on the checkout page in woocommerce. How could I do this using php or javascript ?? Or if there is another better option, I will be happy.

So far, I have used the "code snippets" plugin to add checkboxes. But there's no way to add the feature I need ... at least I think so. :)

Thank you in advance for everything ... I have used this code on the plugin...

    add_action( 'woocommerce_review_order_before_submit', 'bt_add_checkout_checkbox', 10 );
/**
 * Add WooCommerce Checkbox checkout
 */
function bt_add_checkout_checkbox() {
   
    woocommerce_form_field( 'checkout-checkbox', array( // CSS ID
       'type'          => 'checkbox',
       'class'         => array('form-row mycheckbox'), // CSS Class
       '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, // Mandatory or Optional
       'label'         => 'Ok I agree with <a href="/checkout-checkbox" target="_blank" rel="noopener">Checkout Checkbox Page</a>', // Label and Link
    ));    
}

add_action( 'woocommerce_checkout_process', 'bt_add_checkout_checkbox_warning' );
/**
 * Alert if checkbox not checked
 */ 
function bt_add_checkout_checkbox_warning() {
    if ( ! (int) isset( $_POST['checkout-checkbox'] ) ) {
        wc_add_notice( __( 'Please acknowledge the Checkbox' ), 'error' );
    }
}

Can I use it also for select all checkbox??




Aucun commentaire:

Enregistrer un commentaire