I have been trying to figure out how to make my guest checkout-enabled website work but with no success so far. I have the following WooCommerce settings activated:
- Enable guest checkout
- Enable registration on "Checkout" page
Normally, users should be able to checkout without creating an account, but can, however, opt to create an account if they want to. But if I place a test order as guest and check the "Create account?" box + fill out username and password fields, none of the information provided for billing and shipping shows up on the Thank You page or in the WP dashboard. It's as if the "Create account?" box + username and password would be ignored.
I suspect it has something to do with me having changed the default position of the account registration fields. I have added them to the form-login.php file so it shows up in the same section as the login form. They were originally included in the form-billing.php field. Below please find these files:
form-billing.php
<?php
/**
* Checkout billing information form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-billing.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.1.2
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
/** @global WC_Checkout $checkout */
?>
<div id="woocommerce-billing-fields" class="woocommerce-billing-fields">
<h3 class="billing-fields-title">Billing Address</h3>
<?php
do_action('woocommerce_before_checkout_billing_form', $checkout);
?>
<?php
foreach ($checkout->checkout_fields['billing'] as $key => $field):
?>
<?php
woocommerce_form_field($key, $field, $checkout->get_value($key));
?>
<?php
endforeach;
?>
<?php
do_action('woocommerce_after_checkout_billing_form', $checkout);
?>
</div>
form-login.php:
<?php wc_print_notices(); ?>
<?php echo '<div class="panel-group" id="checkout-accordion">'; ?>
<?php
/**
* Checkout login form
*
* This template can be overridden by copying it to yourtheme/woocommerce/checkout/form-login.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @author WooThemes
* @package WooCommerce/Templates
* @version 2.0.0
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly
}
if (is_user_logged_in() || 'no' === get_option('woocommerce_enable_checkout_login_reminder')) {
return;
}
echo '<div class="panel panel-default checkout-panel" id="panel-login">
<div class="panel-heading checkout-heading" id="panel-login-heading" data-toggle="collapse" data-parent="#checkout-accordion" href="#collapse-login">
<h4 class="panel-title checkout-acc-title"> <a class="accordion-checkout">Login/Register <i id="checkout-accordion-login" class="checkout-accordion-icon"></i></a> </h4>
</div>
<div id="collapse-login" class="panel-collapse details collapse in">
<div class="panel-body checkout-inside"><div class="checkout-left-login"><h3 class="login-option">Login</h3>';
$info_message = apply_filters('woocommerce_checkout_login_message', '<div class="already-registered">' . __('Already registered?', 'woocommerce') . '</div>');
wc_print_notice($info_message, 'notice');
?>
<?php
woocommerce_login_form(
array(
'redirect' => wc_get_page_permalink( 'checkout' ),
'hidden' => true,
)
);
echo '</div>';
?>
<?php
if (!is_user_logged_in() && $checkout->enable_signup):
?>
<?php
if ($checkout->enable_guest_checkout):
?>
<p class="form-row form-row-wide create-account">
<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>
</p>
<?php
endif;
?>
<?php
do_action('woocommerce_before_checkout_registration_form', $checkout);
?>
<?php
if (!empty($checkout->checkout_fields['account'])):
?>
<div class="checkout-right-register">
<h3 class="login-option">Create an Account</h3>
<div class="create-account">
<?php
foreach ($checkout->checkout_fields['account'] as $key => $field):
?>
<?php
woocommerce_form_field($key, $field, $checkout->get_value($key));
?>
<?php
endforeach;
?>
<div class="clear"></div>
</div>
<?php
endif;
?>
<?php
do_action('woocommerce_after_checkout_registration_form', $checkout);
?>
<?php
endif;
?>
<button id="toggle-login" type="button" class="register-btn-checkout" data-toggle="collapse" onclick="setCookie('panel-billing')" data-parent="#checkout-accordion" href="#collapse-billing">Continue</button>
</div><div class="or-select-guest">OR</div><button id="toggle-login2" type="button" class="guest-btn-checkout" data-toggle="collapse" data-parent="#checkout-accordion" href="#collapse-billing" onclick="setCookie('panel-billing')">Checkout as Guest</button>
<?php echo'</div></div></div>';
?>
As a side note: the whole checkout form will be an accordion, with sections for delivery + billing, delivery options, and payment.
Am I missing anything? I suspect the issue might be related to the Woocommerce actions, but I can't tell for sure.