Unhide Checkout Login form for unlogged users in Woocommerce

一曲冷凌霜 提交于 2021-01-29 04:35:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!