0

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 );

1 Answer 1

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 );
2
  • Thank you very much for your reply. I am not sure why but it seems that html is not recognized at all for both codes. And I keep seeing the code in plain text. Just let you an URL maybe it help to understand. imgur.com/NPLsiZp Commented Nov 8, 2021 at 8:10
  • Ah, because this is a Woocommerce I didn't realize that filter is run through esc_html (this is how it's being called: github.com/woocommerce/woocommerce/blob/3.8.0/templates/…). That is really only meant to display text only. You could try the solution listed here: wordpress.org/support/topic/… -OR- do something like this: aceplugins.com/… Commented Nov 8, 2021 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.