How to make checkbox checked by default? In Woocommerce checkout
Asked Answered
R

3

6

Have a wordpress site with woocommerce

I installed the Getresponse Woocommerce Integration plugin and really need the checkbox at checkout to be TICKED by default (they tick a box "sign up to our newsletter" to join our email list)

Been trying everything, would really appreciate help on how to do this?

I suspect I should change something in line 394 of getresponse_integration.php

<input class="input-checkbox" value="1" id="checkout_checkbox" type="checkbox" name="checkout_checkbox">

Have tried inserting things like "checked" like this:

<input class="input-checkbox" value="1" id="checkout_checkbox" type="checkbox" name="checkout_checkbox" checked>

This makes the box appear checked at checkout but it the emails DO NOT get passed to the list, so I dont receive any welcome email and are not subscribed. Funnily enough if I manually untick the box and retick then it works

Have tried other things like class=selected and no luck??

Would really appreciate some help please?

P.S. Have tried getresponse support and they are no help at all

http://wordpress.org/plugins/getresponse-integration/

Rotifer answered 20/2, 2014 at 10:29 Comment(0)
A
8

You need to add the following code to your functions.php

add_filter( 'woocommerce_create_account_default_checked', '__return_true' );
Acquirement answered 14/5, 2015 at 17:38 Comment(1)
Much cleaner implementation than the selected answer!Twannatwattle
I
5

You could use jQuery to automatically check the box on page load like this:

<script>
$(document).ready(function () {
    $('#checkout_checkbox').attr('checked', 'checked');
});
</script>

I hope you find this helpful!

Interrogate answered 20/2, 2014 at 12:25 Comment(3)
Hi Danyo, Thanks that does sound useful, where and how exactly would I insert that as have tried all sorts of different places and getting errors? Also presume I replace Your Checkbox ID with checkbox_checked, do I take out the #, anything else to change in the code?Rotifer
I have updated the code to your exact requirements. The best place for this would be in the footer of your site, anywhere after where jQuery has been included.Interrogate
You should accept my answer, so people who view this in the future get the right answer :)Interrogate
P
5

There are hooks provided to do this already. All you need to do is add this to your themes functions.php file. The advantage is that you wont loose the changes when woocommerce files get updated.

add_filter( 'woocommerce_terms_is_checked_default', 'apply_default_check' );
function apply_default_check() 
{
    return 1;
}
Punchy answered 14/12, 2016 at 9:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.