duanpaxin3531 2018-07-09 09:08
浏览 51
已采纳

在Woocommerce 3.1中更改wc_empty_cart_message函数

I've been trying to change my layout for the empty-cart message. I've removed the action, and try to replace it.

I'd like to change the htm structure output from:

<p class="empty-cart"></p> 

to:

<div class="col-12 offset-md-1 col-md-10"><p class="empty-cart"></p></div>

My actual code (in functions.php file of my theme):

/** Change the output for empty-cart within a div */
remove_action( 'wc_empty_cart_message', 'wc_empty_cart_message', 10 );
add_action( 'wc_empty_cart_message', 'wc_empty_cart_message', 10 );

function custom_wc_empty_cart_message() {
echo '<div class="col-12 offset-md-1 col-md-10"><p class="cart-empty">'
. wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) ) ) . '</p></div>';
}

But this code doesn't work. Does anyone has a suggestions on how to make this work?

  • 写回答

1条回答 默认 最新

  • douti6740 2018-07-09 21:35
    关注

    Here below is the correct way to make it work:

    remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );
    add_action( 'woocommerce_cart_is_empty', 'custom_empty_cart_message', 10 );
    
    function custom_empty_cart_message() {
        $html  = '<div class="col-12 offset-md-1 col-md-10"><p class="cart-empty">';
        $html .= wp_kses_post( apply_filters( 'wc_empty_cart_message', __( 'Your cart is currently empty.', 'woocommerce' ) ) );
        echo $html . '</p></div>';
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动