![](/img/trans.png)
[英]Add an informative custom message in Woocommerce Checkout page
[英]Display a Custom Message in Woocommerce Checkout page
此解决方案基于在 Woocommerce 结帐页面中添加信息丰富的自定义消息
我创建了一条自定义消息,但不确定语法是否正确。 它在前端显示良好,但需要帮助来检查它。
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()
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' );
}
两者都有效。
现在,如果您在开头不需要“信息:”字符串,只需使用:
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' );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.