Archived topic
"Previous" and "Next" buttons in Woocommerce
25 replies · Started by Alberto on July 31, 2018
Hi!
I would like to know if there is any way to place "previous" and "following" buttons on the Woocommnerce product pages, so that you can navigate from one product to another without having to return to the product category page.
Thank you in advance.
Hi there,
You can try this how to:
https://businessbloomer.com/woocommerce-add-nextprevious-single-product-page/
Hello David! Thank you very much for your reply.
I would appreciate it if you could indicate where I should place those codes within Generatepress.
Thank you very much!
So the first code is PHP:
https://docs.generatepress.com/article/adding-php/
If you're not using a Child theme i would suggest the Code Snippets plugin, a link to which is in the above article
Second is CSS:
https://docs.generatepress.com/article/adding-css/
David.
I have placed the php code using the Code Snippets plugin. I also placed the additional CSS from Customize> Additional CSS, however the previous and next arrows do not appear on the Woocommerce product page ...
I think I followed the steps correctly ...
I have to win something more from Generapress?
Thank you in advance.
Aah ok, that code works by skipping through the Product Categories, which it looks like your products don't have any?
Try adding a base category to some of the products and see if that works.
All the products belong to a category (you can see it from the accordion menu on the right). I have the breadcrumb disabled from Generatepress, although activating it does not make any difference either ...
That's weird.
In your PHP code, find this line:
echo $previous;
On the line above it, do this:
var_dump($previous);
So it should look like this:
var_dump($previous);
echo $previous;
That will output some debugging data where the links should show up. Can you share that data with me?
Hello Tom.
After placing the code, it now appears, on the left side NULL
Weird, so that core WP function isn't working..
Try this:
add_action( 'woocommerce_before_single_product_summary', 'tu_prev_next_product' );
function tu_prev_next_product(){
echo '<div class="prev_next_buttons">';
next_post_link( '%link', '← Previous', true, false, 'product_cat' );
previous_post_link( '%link', 'Next →', true, false, 'product_cat' );
echo '</div>';
}
Hello, good morning Tom.
I changed the code I had for this one that you passed me and the previous and next arrows still do not show ...
I no longer know what the error may be.
Thank you very much for your help.
Just made a small change, can you give it another shot?: https://generatepress.com/forums/topic/previous-and-next-buttons-in-woocommerce/#post-637396
Tom.
Unfortunately, it still does not work
Hmm, this has me stumped! Let me do some testing - I'll get back to you.
Ok, thank you very much and I await your response.