此解决方案基于 Add an informative custom message in Woocommerce Checkout page
我创建了一条自定义消息,但不确定语法是否正确。它在前端显示良好,但需要帮助检查。
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' );
}
答案 0 :(得分:2)
您的 sprintf()
内容中缺少一点(占位符):
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' );
}
或不使用 sprintf()
函数:
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' );
}
两者都有效。
现在,如果您不需要 "Information:" 开头的字符串,只需使用:
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' );
}