I want to show Previous category and Next category links in a category archive page in woocommerce template. I got this code from another post but for me errors are coming. These are the errors,
Catchable fatal error: Object of class WP_Error could not be converted to string in [FILE] and undefined variable for $next_cat and $prev_cat
$this_category = get_queried_object(); $categories = get_categories(); foreach( $categories as $position => $cat ) : if( $this_category->term_id == $cat->term_id ) : $next_cat = $position + 1; $prev_cat = $position - 1; break; endif; endforeach; $next_cat = $next_cat == count($categories) ? 0 : $next_cat; $prev_cat = $prev_cat < 0 ? count($categories) - 1 : $prev_cat; echo 'previous: ' . get_term_link( $categories[$prev_cat] ); echo 'next: ' . get_term_link( $categories[$next_cat] );
Any help is appreciated.