Created
November 22, 2022 16:11
-
-
Save MrJoshFisher/c43c0b1bee6d7146e1403b8578877824 to your computer and use it in GitHub Desktop.
[Checkbox to Checkout] #wordpress #woocommerce
This file contains hidden or 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_action( 'woocommerce_review_order_before_submit', 'bt_add_checkout_checkbox', 10 ); | |
/** | |
* Add WooCommerce additional Checkbox checkout field | |
*/ | |
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' => 'I accept that the classes are non refundable or transferable.', // 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' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment