问题
When a customer is not logged in, I want the Woocommerce login form to not be initially hidden on the checkout page. I would also like the create an account? Radio to be ticked like the subscribe button is by default.
Thanks
回答1:
The following hooked function will enable the login form by default for unlogged users
// Enable the login form by default for unlogged users
add_action( 'woocommerce_before_checkout_form', 'force_checkout_login_for_unlogged_customers', 4 );
function force_checkout_login_for_unlogged_customers() {
if( ! is_user_logged_in() ) {
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_login_form', 10 );
add_action( 'woocommerce_before_checkout_form', 'custom_checkout_login_form', 20 );
}
}
function custom_checkout_login_form() {
wc_get_template( 'global/form-login.php', array(
'message' => __( 'If you have shopped with us before, please enter your details below. If you are a new customer, please proceed to the Billing & Shipping section.', 'woocommerce' ),
'redirect' => wc_get_page_permalink( 'checkout' ),
'hidden' => false,
) );
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
来源:https://stackoverflow.com/questions/53132754/unhide-checkout-login-form-for-unlogged-users-in-woocommerce