WordPress Tricks

Add additional Continue Shopping button beside View Cart which linked to the Added Product Category page

Just wanted to add an additional button in the woocommerce message bar and beside the View Cart button, which will be linked to the added product category page.

function filter_wc_add_to_cart_message_html( $message, $products ) { 
global $wp_query;
//echo $products[0] ;
$catID=array_keys($products);
$catID=$catID[0];
 	
 $terms = get_the_terms($catID, 'product_cat' );
 
 
foreach ($terms  as $term  ) {
            $product_cat_id = $term->term_id;
            $product_cat_name = $term->name;
            break;
        }	
$productCategoryUrl = get_category_link($product_cat_id);	
 
 $continue   = '<a href="'.$productCategoryUrl.'" class="button wc-forward cat"> Continue shopping </a>'; 
        
    $message .= $continue;
    return $message; 
}; 

add_filter( 'wc_add_to_cart_message_html', 'filter_wc_add_to_cart_message_html', 10, 2 );

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s