在WooCommerce 3.1中更改wc_empty_cart_message函数 [英] Change wc_empty_cart_message function in WooCommerce 3.1

查看:189
本文介绍了在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.

我想将htm结构的输出更改为:

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

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

收件人:

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

我的实际代码(在我主题的functions.php文件中):

/** 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?

推荐答案

以下是使其正常工作的正确方法:

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

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

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

要删除空的购物车消息,只需使用:

To remove empty cart message use just:

remove_action( 'woocommerce_cart_is_empty', 'wc_empty_cart_message', 10 );

这篇关于在WooCommerce 3.1中更改wc_empty_cart_message函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆