在 Woocommerce 结帐页面中显示自定义消息

问题描述

解决方案基于 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' );
}

解决方法

您的 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',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',10 );
function print_webcache_notice() {
    wc_print_notice( __("Having trouble checking out? Please clear your web browser cache!",'success' );
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...