WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
How to set a checkbox to checked as default (8 posts)

  1. dEM0nsTAr
    Member
    Posted 1 year ago #

    I want to change

    <?php if ( ! is_user_logged_in() && $checkout->enable_signup ) : ?>
    
    	<?php if ( $checkout->enable_guest_checkout ) : ?>
    
    		<p class="form-row form-row-wide">
    			<input class="input-checkbox" id="createaccount" <?php checked($checkout->get_value('createaccount'), true) ?> type="checkbox" name="createaccount" value="1"/> <label for="createaccount" class="checkbox"><?php _e( 'Create an account?', 'woocommerce' ); ?></label>
    		</p>

    to

    <?php if ( ! is_user_logged_in() && $checkout->enable_signup ) : ?>
    
    	<?php if ( $checkout->enable_guest_checkout ) : ?>
    
    		<p class="form-row form-row-wide">
    			<input class="input-checkbox" id="createaccount" <?php checked($checkout->get_value('createaccount'), true) ?> type="checkbox" name="createaccount" value="1" checked="checked"/> <label for="createaccount" class="checkbox"><?php _e( 'Create an account?', 'woocommerce' ); ?></label>
    		</p>

    with the help of a functions.php to survive WooCommerce updates (see the different checked="checked" part).
    How can I do that?
    Thanks

    http://wordpress.org/extend/plugins/woocommerce/

  2. IgniteWoo
    Member
    Posted 1 year ago #

    Get rid of this aspect:

    <?php checked($checkout->get_value('createaccount'), true) ?>
  3. dEM0nsTAr
    Member
    Posted 1 year ago #

    What do you mean?
    I have only pasted the original code which came with WooCommerce 2.0.9 and I am looking for a persistent solution to make the checkbox to create a new account checked as default even after WooCommerce updates.

  4. IgniteWoo
    Member
    Posted 1 year ago #

    Modify the billing form template ( form-billing.php ) . Move a copy to your theme, then edit it. No function required. See the WooCommerce documentation for how to copy templates to your theme directory.

  5. dEM0nsTAr
    Member
    Posted 1 year ago #

    Isn't it possible with a functions.php solution?
    Would be one file less to create and easier to adapt to changes.

  6. IgniteWoo
    Member
    Posted 1 year ago #

    Either way you're likely to be subject to adaptations at some point or other down the road.

  7. dEM0nsTAr
    Member
    Posted 1 year ago #

    I have added a pull request in GitHub now: https://github.com/woothemes/woocommerce/pull/3098

  8. dereksan
    Member
    Posted 2 months ago #

    WooCommerce (at least in version 2.1.7) has an apply-filters tag in that checked statement now:
    (from default form-billing.php):
    <input class="input-checkbox" id="createaccount" <?php checked( ( true === $checkout->get_value( 'createaccount' ) || ( true === apply_filters( 'woocommerce_create_account_default_checked', false ) ) ), true) ?> type="checkbox" name="createaccount" value="1" /> <label for="createaccount" class="checkbox"><?php _e( 'Create an account?', 'woocommerce' ); ?></label>

    So, simply adding this statement in functions.php should work:
    add_filter( 'woocommerce_create_account_default_checked', function( $isChecked) { return true; } );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.