为什么仍然出现“添加到购物车”消息?

时间:2019-03-27 08:48:28

标签: php wordpress function woocommerce

我为WooCommerce编写了一条自定义的“添加到购物车”消息,此后,我使用条件标签“ is_cart()”在购物车页面上禁用了该消息,但该消息仍然显示。

如何禁用购物车页面上显示的消息?

这是我的代码示例:

function iw_add_to_cart_message_function( $message, $product_id ) {

    if (!is_cart()) {

        $message    = sprintf(esc_html__('%s has been added by to your cart pompidompidom.','iwebbers'), get_the_title( $product_id ) );

        return $message;

    }
}

add_filter( 'wc_add_to_cart_message', 'iw_add_to_cart_message_function', 10, 2 );

我刚刚尝试了以下IF STATEMENT,它可以正常工作:

global $woocommerce;
if (get_option('woocommerce_cart_redirect_after_add')=='no') {

1 个答案:

答案 0 :(得分:1)

功能wc_add_to_cart_message

返回而不是添加消息。

转到引用链接:docs.woocommerce