Woocommerce for WP 中 wc_add_to_cart_message 钩子的替代方案 [英] Alternative for the wc_add_to_cart_message hook in Woocommerce for WP

查看:41
本文介绍了Woocommerce for WP 中 wc_add_to_cart_message 钩子的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Woocommerce 中的添加到购物车消息挂钩来编辑文本并从某些按钮中删除一些类.似乎这个钩子现在在 Woocommerce 2.1 中被弃用了,我找不到替代方案.

I used the add to cart message hook in Woocommerce to edit the text and remove some classes from certain buttons. It seems this hook is now deprecated in Woocommerce 2.1 and I can't find an alternative.

我想从继续购物"按钮中删除按钮"类.这个类是在 Woocommerce 核心中定义的,我想保留它以供将来正确更新.

I want to remove the 'button' class from the 'Continue Shopping' button. This class gets defined in the Woocommerce core which I want to leave unedited for proper future updates.

我要编辑的行位于 woocommerce/includes/wc-cart-functions.php 第 94 行.

The line I'm trying to edit is located in woocommerce/includes/wc-cart-functions.php line 94.

$message = sprintf('<a href="%s" class="button wc-forward">%s</a> %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text );

有没有人为这个钩子找到合适的替代品?提前致谢!

Did anyone find a proper alternative for this hook yet? Thanks in advance!

推荐答案

这对我有用

add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
function custom_add_to_cart_message() {
    global $woocommerce;

        $return_to  = get_permalink(woocommerce_get_page_id('shop'));
        $message    = sprintf('<a href="%s" class="button wc-forwards">%s</a> %s', $return_to, __('Continue Shopping', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
    return $message;
}

已感谢 Kaarel Kaspar 的更正

Edited: Thanks for the correction Kaarel Kaspar

这篇关于Woocommerce for WP 中 wc_add_to_cart_message 钩子的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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