简体   繁体   English

在 WooCommerce 登录页面重新定位自定义注册链接

[英]Repositioning a custom registration link on WooCommerce login page

I have a WooCOmmerce Login Page which I am customizing at the moment, by default the login and registration page are in one page.我目前正在自定义一个 WooCOmmerce 登录页面,默认情况下,登录和注册页面在一个页面中。 I had seperated the login and registration pages into 2 seperate forms right now.我现在将登录和注册页面分成 2 个单独的 forms。 Currently I would like to put a link for the seperated registration page right below the "Forgot Password" link.目前我想在“忘记密码”链接下方放置一个单独的注册页面链接。

But my output is as follows:但是我的output如下:

电流输出

I would like for it to appear as follows:我希望它显示如下:

预期输出

Below is the action hook I am using for my login page.下面是我用于登录页面的操作挂钩。

add_action( 'woocommerce_after_customer_login_form', 'register_link' );
function register_link() {

    ?>
        <div class="woocommerce-register-link">
            <p><?php _e( '<a href="Registration page Link/">Register a new account here</a>' ); ?></p>
        </div>
    <?php
    
}

Any help would be much appreciated.任何帮助将非常感激。

This can be done in multiple ways:这可以通过多种方式完成:

  1. You can edit the template myaccount/form-login.php to insert your code in the right location.您可以编辑模板myaccount/form-login.php以将代码插入正确的位置。

  2. you can use Javascript/jQuery to insert your code in the right location, without editing any template:您可以使用 Javascript/jQuery 将代码插入正确的位置,而无需编辑任何模板:

// The jQuery Ajax request
add_action( 'wp_footer', 'wc_separated_login_form_js' );
function wc_separated_login_form_js() {
    // Only my account for unlogged users
    if( ! is_user_logged_in() && is_account_page() &&
    'yes' === get_option('woocommerce_enable_myaccount_registration') ):

    // Your button html to insert
    $html = sprintf(
        '<p class="woocommerce-Registerlink register-link"><a href="%s">%s</a></p>',
        home_url('/registration/'), // <== Here set your registration link
        __( 'Register a new account here')
    );

    // jQuery
    ?>
    <script type="text/javascript">
    jQuery( function($){
        $('p.lost_password').after('<?php echo $html; ?>');
    });
    </script>
    <?php
    endif;
}

Code goes in functions.php file of your active child theme (or active theme).代码进入您的活动子主题(或活动主题)的functions.php 文件。 Tested and works.测试和工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM