我在尝试通过我的主题 functions.php 文件更改消息的输出时遇到问题。
这是 woocommerce 插件提供的代码:
function woocommerce_add_to_cart_message() {
global $woocommerce;
if (get_option('woocommerce_cart_redirect_after_add')=='yes') :
$return_to = (wp_get_referer()) ? wp_get_referer() : home_url();
$message = sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
else :
$message = sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart →', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
endif;
$woocommerce->add_message( apply_filter('woocommerce_add_to_cart_message', $message) );
}
我想要做的是更改按钮消息,但我不完全确定如何执行此操作。
我一直在阅读 WP 法典,但不幸的是,我认为我不太了解它是如何工作的。这是我尝试过的:
function remove_woocommerce_add_to_cart_message() {
remove_filter('woocommerce_add_to_cart_message', $message) ;
}
function woocommerce_add_to_cart_message_edited() {
global $woocommerce;
if (get_option('woocommerce_cart_redirect_after_add')=='yes') :
$return_to = (wp_get_referer()) ? wp_get_referer() : home_url();
$message = sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
else :
$message = sprintf('<a href="%s" class="button">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('NEW CART MESSAGE', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
endif;
$woocommerce->add_message( apply_filter('woocommerce_add_to_cart_message', $message) );
}
因此,我尝试删除输出消息的过滤器,然后声明它,但它似乎不起作用。
任何帮助将不胜感激!