How to execute init or woocommerce_init only for checkout page
I am making extra function for my own project.
function devsol_customer_login() {
if ( is_checkout() ) { ?
form method="post"
input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="username" id="username" autocomplete="username" value="?php echo ( ! empty( $_POST['username'] ) ) ? esc_attr( wp_unslash( $_POST['username'] ) ) : ''; ?" /
button type="submit" class="woocommerce-Button button woocommerce-form-login__submit" name="login" value="?php esc_attr_e( 'Log in', 'woocommerce' ); ?"?php esc_html_e( 'Log in', 'woocommerce' ); ?/button
/form
?php
$user_phone = sanitize_text_field( $_POST['username'] );
if ( $user = get_user_by( 'login', $user_phone) ) {
$user_id = $user-ID;
$user_roles = $user-roles;
$user_role = array_shift($user_roles);
if ( $user_role === 'customer') {
echo 'Yes Customer';
if ( apply_filters( 'woocommerce_registration_auth_new_customer', true, $user_id ) ) {
wc_set_customer_auth_cookie( $user_id );
}
}
}
echo 'Home';
}
}
add_action('woocommerce_init', 'devsol_customer_login');
But the function is not executing on checkout page. Can someone help