微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决在 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' );
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。