Skip to content

Instantly share code, notes, and snippets.

@softiconic
Last active December 2, 2023 18:33
Show Gist options
  • Save softiconic/e67bd602f90466fe47c310e16b427446 to your computer and use it in GitHub Desktop.
Save softiconic/e67bd602f90466fe47c310e16b427446 to your computer and use it in GitHub Desktop.
WooCommerce single product - navigate to the next or previous product.
//add_action( 'woocommerce_before_single_product', 'add_custom_text_before_product_title' );
add_shortcode( 'scnextprev', 'productnextprev_shortcode' );
function productnextprev_shortcode(){
echo '<div class="prev_next_buttons">';
// 'product_cat' will make sure to return next/prev from current category
$previous = next_post_link('%link', '&larr; %title', TRUE, ' ', 'product_cat');
$next = previous_post_link('%link', '%title &rarr;', TRUE, ' ', 'product_cat');
echo $previous;
echo $next;
echo '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment