Created
January 15, 2021 09:41
-
-
Save daveloodts/67473ca072f613fb4f1175b2463504dc to your computer and use it in GitHub Desktop.
Verplichte checkbox toevoegen in WooCommerce + notificatie indien niet ingevuld
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add WooCommerce Checkbox checkout | |
*/ | |
add_action( 'woocommerce_review_order_before_submit', 'woofers_add_checkout_checkbox', 10 ); | |
function woofers_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' => 'Yes, I agree with <a href="/return-policy/" target="_blank" rel="noopener"><u>return policy</u>.</a><br/>Sales, under € 30 items and accessories are non-returnable. All other items can be send back within 14 days in return for a gift certificate.', // 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 agree with our return policy to order' ), 'error' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment