admin管理员组

文章数量:1279048

I use the option that people need to have an account to checkout. So the checkout page is blocked. At that moment you’ll get the message “You must be logged in to checkout”.

To improve that customers don’t have to search where to click next, i want to add extra text with an hyperlink.

I found this code work perfectly but HTML is not working inside ‘MY MESSAGE’ area.

function filter_woocommerce_checkout_must_be_logged_in_message( $message ) {
    $message = 'MY MESSAGE';
    return $message; 
}
add_filter( 'woocommerce_checkout_must_be_logged_in_message', 'filter_woocommerce_checkout_must_be_logged_in_message', 10, 1 );

So far i got this but html is not working on my end.

function filter_woocommerce_checkout_must_be_logged_in_message( $message ) {
    $message = '<span>You must be <a href="#"logged in</a></span>';
    return $message; 
}
add_filter( 'woocommerce_checkout_must_be_logged_in_message', 'filter_woocommerce_checkout_must_be_logged_in_message', 10, 1 );

I use the option that people need to have an account to checkout. So the checkout page is blocked. At that moment you’ll get the message “You must be logged in to checkout”.

To improve that customers don’t have to search where to click next, i want to add extra text with an hyperlink.

I found this code work perfectly but HTML is not working inside ‘MY MESSAGE’ area.

function filter_woocommerce_checkout_must_be_logged_in_message( $message ) {
    $message = 'MY MESSAGE';
    return $message; 
}
add_filter( 'woocommerce_checkout_must_be_logged_in_message', 'filter_woocommerce_checkout_must_be_logged_in_message', 10, 1 );

So far i got this but html is not working on my end.

function filter_woocommerce_checkout_must_be_logged_in_message( $message ) {
    $message = '<span>You must be <a href="#"logged in</a></span>';
    return $message; 
}
add_filter( 'woocommerce_checkout_must_be_logged_in_message', 'filter_woocommerce_checkout_must_be_logged_in_message', 10, 1 );
Share Improve this question edited Nov 8, 2021 at 8:33 Stéphane Dumas asked Nov 5, 2021 at 8:41 Stéphane DumasStéphane Dumas 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You are missing a closing tag for the opening link (<a>) tag, try:

function filter_woocommerce_checkout_must_be_logged_in_message( $message ) {
    $message = '<span>You must be <a href="#">logged in</a></span>';
    return $message; 
}
add_filter( 'woocommerce_checkout_must_be_logged_in_message', 'filter_woocommerce_checkout_must_be_logged_in_message', 10, 1 );

(You could also just spit out the login form right there instead of linking off, if you wanted):

function filter_woocommerce_checkout_must_be_logged_in_message( $message ) {
        $login_form = wp_login_form( [ 'echo' => false ] );
        $message = '<p>You must be logged in:</p>';
        $message .= $login_form;
        return $message; 
    }
    add_filter( 'woocommerce_checkout_must_be_logged_in_message', 'filter_woocommerce_checkout_must_be_logged_in_message', 10, 1 );

本文标签: woocommerce offtopicAdd html link in functionsphp files of the theme