Display a Custom Message in Woocommerce Checkout page

1.7k views Asked by At

This solution is based on Add an informative custom message in Woocommerce Checkout page

I've created a custom message but not sure if the syntax is correct. It displays fine on the front end, but need help to check it.


add_action( 'woocommerce_before_checkout_form', 'print_webcache_notice', 10 );
function print_webcache_notice() {
    wc_print_notice( sprintf(
        __("Having trouble checking out? Please clear your web browser cache!", "woocommerce"),
        '<strong>' . __("Information:", "woocommerce") . '</strong>',), 'success' );
}

1

There are 1 answers

0
LoicTheAztec On BEST ANSWER

There was a little missing thing in your sprintf() content (the placeholder):

add_action( 'woocommerce_before_checkout_form', 'print_webcache_notice', 10 );
function print_webcache_notice() {
    wc_print_notice( sprintf(
        __("%sHaving trouble checking out? Please clear your web browser cache!", "woocommerce"),
        '<strong>' . __("Information:", "woocommerce") . '</strong> '
    ), 'success' );
}

or without using sprintf() function:

add_action( 'woocommerce_before_checkout_form', 'print_webcache_notice', 10 );
function print_webcache_notice() {
    $message  = '<strong>' . __("Information:", "woocommerce") . '</strong> ';
    $message .= __("Having trouble checking out? Please clear your web browser cache!", "woocommerce");

    wc_print_notice( $message, 'success' );
}

Both work.

Now if you don't need "Information:" string at the beginning, simply use:

add_action( 'woocommerce_before_checkout_form', 'print_webcache_notice', 10 );
function print_webcache_notice() {
    wc_print_notice( __("Having trouble checking out? Please clear your web browser cache!", "woocommerce"), 'success' );
}