在 Woocommerce 结帐页面中显示自定义消息
Display a 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' );
}
您的 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' );
}
两者都有效。
现在如果不需要"信息:"开头的字符串,只需使用:
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' );
}
此解决方案基于
我创建了一条自定义消息,但不确定语法是否正确。在前端显示正常,但需要帮助检查。
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' );
}
您的 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' );
}
两者都有效。
现在如果不需要"信息:"开头的字符串,只需使用:
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' );
}