Remove link to hidden product from nav menu with Product Visibility by User Role
-
When hiding products from unregistered users with Product Visibility by User Role (using either one or both ticks under the Modify Query setting) the link to the product is removed everywhere except from the in-product next/prev navigation.
The original code in the theme that generates this navigation is as such:
if ( ! function_exists( 'shopkeeper_product_nav' ) ) : function shopkeeper_product_nav( $nav_id ) { global $wp_query, $post; // Don't print empty markup on single pages if there's nowhere to navigate. if ( is_single() ) { $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true ); $next = get_adjacent_post( false, '', false ); if ( ! $next && ! $previous ) return; } // Don't print empty markup in archives if there's only one page. if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) ) return; $nav_class = ( is_single() ) ? 'product-navigation' : 'paging-navigation'; ?> <nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo esc_attr( $nav_class ); ?>"> <div class="product-nav-previous"><?php previous_post_link( '%link', '<i class="spk-icon spk-icon-left-small"></i><span>' . esc_html__( 'Previous Product', 'shopkeeper' ) . '</span>' ); ?></div> <div class="product-nav-next"><?php next_post_link( '%link', '<span>' . esc_html__( 'Next Product', 'shopkeeper' ) . '</span><i class="spk-icon spk-icon-right-small"></i>' ); ?></div> </nav><!-- #<?php echo esc_html( $nav_id ); ?> --> <?php } endif; // shopkeeper_product_nav
Since this function can be overridden in my child theme, can you suggest what can be done to remove hidden products from the prev/next navigation for users not authorised to see particular products?
The page I need help with: [log in to see the link]
- The topic ‘Remove link to hidden product from nav menu with Product Visibility by User Role’ is closed to new replies.