简体   繁体   中英

WooCommerce - My account Page add anchor link to the REGISTER section

So I'm trying instead of splitting the WooCommerce My Account page into a separate Login and Register pages, to have an anchor link placed in from of the title REGISTER above of the register form for example <a href="#register"></a> REGISTER

That way I could have a Sign Up link straight to this section in mobile.

I found this function to replace the title "Register" for anything you want. But it won't render the html:

function register_text( $translated ) {
    $translated = str_ireplace('Register',  '<a href="#register"></a> REGISTER',  $translated);
    return $translated;
}

add_filter(  'gettext',  'register_text'  );
add_filter(  'ngettext',  'register_text'  );

See how it looks: https://pasteboard.co/JLk3GBS.png

Any thoughts?

FYI: I'm using Flatsome theme.

This is because the text of this section is replaced with esc_html .

You can easily do this using the wp_is_mobile function and the woocommerce_login_form_end hook:

add_action( 'woocommerce_login_form_end', 'ywp_add_register_anchor_text' );
function ywp_add_register_anchor_text() {
    if( ! wp_is_mobile() ) {
        return;
    }
    echo '<a href="#register"></a>';
}

You can also use the woocommerce template editing method.

Code goes in the functions.php file of your active theme/child theme. Tested and works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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