在Woocommerce结账页面显示自定义信息。

3
这个解决方案是基于在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' );
}

1个回答

4
您的 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' );
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接