Woocommerce “added to cart” message on main(home) page


I am currently making an e-shop on woocommerce. On my homepage there is products slider with the add-to-cart button under each product. If I click on the button, product is added to cart successfully, but without any message.

While surfing the Internet, I’ve found out, that messages can be added on shop page, product category page and product tag page (in this article). According to that article, I should use filter/hook to catch the add-to-cart event and display message on main page.

I have tried this:

    add_filter( 'woocommerce_add_to_cart_message', 'custom_add_to_cart_message' );
    function custom_add_to_cart_message() {
        global $woocommerce;
        // Output success messages
        if (get_option('woocommerce_cart_redirect_after_add')=='yes') :
            $return_to  = get_permalink(woocommerce_get_page_id('shop'));
            $message    = sprintf('<a href="%s" class="button">%s</a> %s', $return_to, __('Continue Shopping &rarr;', '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 &rarr;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );
        return $message;

but nothing happens. Can anyone help me?

WPTricks 4 months 0 Answers 21 views 0

Leave an answer