WooCommerce next/previous tag script

I am trying to make a next/previous tag script for WooCommerce. See the Example below.

Example: In case the tag order is #3 to display #1 and #2 … if #4 to display #3 and #5.

Read More

My current code is not working properly.

PHP:

               <?php         if(is_product_tag()) {  
                            $current_term = get_query_var('term');
                            $current_term_id = get_term_by( 'slug', $current_term, 'product_tag', OBJECT );
                            $terms = get_terms( 'product_tag',array("hide_empty"=>1,"number"=>2,'orderby'=>'id',  "order"=>"ASC", "exclude_tree"=>array($current_term_id->term_id)),ARRAY_A);
                            $i=1;
                            foreach ($terms as $term)
                            {
                             if($i==1) {
                                $leftlink = '<a href="'.get_term_link($term->term_taxonomy_id).'">'.$term->name.'</a>';
                             }
                             else {
                                $rightlink = '<a href="'.get_term_link($term->term_taxonomy_id).'">'.$term->name.'</a>';
                             }
                             $i++;

                            }

                        } ?>

HTML:

<div class="tag-list">
    <span class="previous-box"><?php echo $leftlink;?></span>
    <span class="current-box"><?php woocommerce_page_title(); ?></span>
    <span class="next-box"><?php echo $rightlink;?></span>          
</div>

It would be great if someone can help me!

Best regards,

Tim

Related posts