Woocommerce return to category button in message

I’m trying to add a button so users can go back to the current category they are buying a product. In order to do this, i would like this button to appear once they buy a product, specifically in the message, so my code goes like this:

function wc_add_to_cart_message( $product_id ) {
    $titles = array();

    if ( is_array( $product_id ) ) {
        foreach ( $product_id as $id ) {
            $titles[] = get_the_title( $id );
        }
    } else {
        $titles[] = get_the_title( $product_id );
    }

    $titles     = array_filter( $titles );
    $added_text = sprintf( _n( '%s has been added to your cart.', '%s have been added to your cart.', sizeof( $titles ), 'woocommerce' ), wc_format_list_of_items( $titles ) );

    // Output success messages
    if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) ) {
        $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
        $message   = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue Shopping', 'woocommerce' ), esc_html( $added_text ) );

    } else {

 $product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );

        $single_cat = array_shift( $product_cats ); 

$message = '<a class="button wc-forward" href="http://website/newstore/category/campamentos/' . $single_cat->slug . ' ">Continue Shopping</a>';

        $message   .= sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( wc_get_page_permalink('cart') ), esc_html__( 'View Cart', 'woocommerce' ), esc_html( $added_text ) );


    }

    wc_add_notice( apply_filters( 'wc_add_to_cart_message', $message, $product_id ) );
}

It works good, but i can’t get the continue shopping button to have the last part of the link assigned here >

Read More
$message = '<a class="button wc-forward" href="http://website/newstore/category/campamentos/' . $single_cat->slug . ' ">Continue Shopping</a>';

Guess is because i’m not using echo with $single_cat->slug??

Related posts