【问题标题】:Display a Custom Message in Woocommerce Checkout page在 Woocommerce 结帐页面中显示自定义消息
【发布时间】:2021-06-07 09:41:27
【问题描述】:

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

【问题讨论】:

    标签: php wordpress woocommerce checkout notice


    【解决方案1】:

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

    两者都有效。

    现在,如果您不需要 "Information:" 字符串开头,只需使用:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-23
      • 2021-09-06
      • 2020-02-22
      • 2019-01-22
      • 2016-07-29
      • 2013-06-16
      • 2019-04-14
      • 2021-04-24
      相关资源
      最近更新 更多