Skip to content

Instantly share code, notes, and snippets.

@digamber89
Last active February 21, 2019 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digamber89/e9f2c2d160feae563b2edfc15d24eb4f to your computer and use it in GitHub Desktop.
Save digamber89/e9f2c2d160feae563b2edfc15d24eb4f to your computer and use it in GitHub Desktop.
Quick Fix Terms and Conditions
<?php
add_action( 'woocommerce_after_checkout_validation', 'digthis_two_step_checkout_validate', 9999, 2 );
function digthis_two_step_checkout_validate( $data, $errors ) {
$step = filter_input( INPUT_POST, 'current_step' );
if ( empty( $errors->errors ) && $step == 'step-1' ) {
$errors->add( 'digthis', __( '<span id="digthis-prevent-error">Digthis Error</span>', 'woocommerce' ) );
}
if ( wc_terms_and_conditions_checkbox_enabled() && empty( $errors->errors ) && $step == 'step-1' ) {
$errors->add( 'digthis', __( '<span id="digthis-prevent-error">Digthis Error</span>', 'woocommerce' ) );
}
}
add_filter( 'woocommerce_checkout_posted_data', 'digthis_validate_terms_and_conditions_first_step' );
function digthis_validate_terms_and_conditions_first_step( $data ) {
$step = filter_input( INPUT_POST, 'current_step' );
if ( wc_terms_and_conditions_checkbox_enabled() && $step == 'step-1' ) {
$data['terms'] = 'on';
}
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment