The AutomateWoo plugin adds a checkbox field on the registration section (located on My Account page when user is not logged in) and I am trying here to make it required.
I don’t want people to be able to register without ticking this box.
The box is an optin and displays as follows:
<p class="automatewoo-optin form-row">
<label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
<input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="automatewoo_optin" id="automatewoo_optin">
<span class="automatewoo-optin__checkbox-text">I want to receive updates about products and promotions.</span>
</label>
</p>
Here is my code attempt to make this checkbox "required":
add_filter( 'woocommerce_register_form_start', 'bd_require_automatewoo_optin');
function bd_require_automatewoo_optin( $fields ) {
$fields['automatewoo_optin']['required'] = true;
return $fields;
}
I have also tried using woocommerce_register_form
and woocommerce_forms_field
hooks.
Image preview of the "Register" form, checkbox is located at the bottom.
How can I make Make AutomateWoo checkbox required on WooCommerce registration section?
Edit:
In some cases, you may need to replace the second ‘required’ with ‘true’…
<script>
jQuery(document).ready(function($){
$('input[name="automatewoo_optin"]').prop('required', 'required');
});
</script>
2
Answers
Use jQuery. Either add to your theme scripts, or you can add to
wp_footer
and wrap in<script> </script>
To make your checkbox field located on WooCommerce registration form required, use the following:
Then optionally use also the following to make your checkbox field visually required:
Code goes in functions.php file of the active child theme (or active theme). Tested and works.