- This topic has 25 replies, 5 voices, and was last updated 1 year, 5 months ago by David.
-
AuthorPosts
-
August 2, 2018 at 9:58 am #638806TomLead DeveloperLead Developer
So I just added this function to my test site:
add_action( 'woocommerce_before_single_product', '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>'; }
And it worked: http://prntscr.com/kdwujr
I wonder if you have a plugin that’s conflicting?
August 3, 2018 at 6:09 am #639422AlbertoTom.
I am adding the code through the Code Snippets plugin.
I do not know how you are adding your …
August 3, 2018 at 6:24 am #639429DavidStaffCustomer SupportHi there,
Works fine with Code Snippets.
On your site i can see in the code that the Container is being output to the page, but the nav links are missing.As Tom mentioned it could be a Plugin conflict, can you try disabling plugins to see if this resolves the issue. I would begin with the YITH WC accordion widget……
August 3, 2018 at 6:29 am #639433AlbertoDavid.
I inform you that I have disabled the plugin YITH WooCommerce Category Accordion and the arrows still do not appear …
August 3, 2018 at 6:40 am #639438DavidStaffCustomer SupportCan you work through each of the plugins? Probably best to disable any caches you may have whilst testing.
July 6, 2020 at 9:24 am #1354177SimonHi Tom, David
I have used the Bloomer code you linked to above, and it works. The problem is that the Next and Previous link to the alphabetical next and previous product – but only within same category.
I would like to link to the next and previous product of all the products (alphabetically as they are shown in the ‘shop’). Any help gratefully received…
The key bit of the Bloomer code seems to be this:
$previous = next_post_link(‘%link’, ‘← PREVIOUS’, TRUE, ‘ ‘, ‘product_cat’);
$next = previous_post_link(‘%link’, ‘NEXT →’, TRUE, ‘ ‘, ‘product_cat’);I have inserted %title to get the name of the next and previous plants:
$previous = next_post_link(‘%link’, ‘← %title’, TRUE, ‘ ‘, ‘product_cat’);
$next = previous_post_link(‘%link’, ‘%title →’, TRUE, ‘ ‘, ‘product_cat’);I have read: https://developer.wordpress.org/reference/functions/next_post_link/
and have tried FALSE to the question of being within the category.$previous = next_post_link(‘%link’, ‘← %title’, FALSE);
$next = previous_post_link(‘%link’, ‘%title →’, FALSE);But the result is almost random steps, where Next takes you to a product in which Previous is not the one you came from (if you get my gist!).
It ought to be simple… How can I do it???
Major thank you.
July 6, 2020 at 3:23 pm #1354493TomLead DeveloperLead DeveloperThat should do it, but I know WooCommerce can act weird with post navigation. You can always
var_dump($previous);
to debug what the variable is returning.May be worth opening a new topic if you can’t get it working – this one is quite old.
Thanks!
September 3, 2020 at 8:57 am #1429574KatharineHello,
I have the same issue and I followed the same instructions with Code Snippets and CSS but it’s also not working for me. Would someone be able to help, or point me in the direction of the plugin that could be blocking it?
Or shall I open a new ticket? ๐
Thanks,
KatieSeptember 3, 2020 at 1:50 pm #1429889TomLead DeveloperLead DeveloperA new ticket would be great, especially if you could link us to your site ๐
Thanks!
October 20, 2022 at 3:55 am #2379808Kenny WilliamsonHello Tom, i was also looking for this.
I tried the code that you gave and it does work for me.(magiciansandmagicshop.com).
However, i did notice something else.
If you are using more than one category, it diverts to the next of the primary category (e.g. rankmath give option of a primary category)- so although i might have a product in a primary category of magic downloads, but also have a category linked of magic books- then when scrolling through a magic book and clicking next, it diverts to the next product in magic downloads.So, this is not ideal solution in this use case.
(i am just leaving it, as it at least allows everyone to scroll through to another product- better than not).October 20, 2022 at 5:35 am #2379896DavidStaffCustomer SupportHi there,
thanks for the feedback.
Unfortunately those Primary Categories that RankMath and Yoast add are not core functions.
So the core function that Tom used in his code has no handle on them.It may be possible to filter out ALL other terms if a Primary Category is present. But from past experience i have found Woocommerce does some peculiar things with next / prev navigation. I think this would require a dedicated Woocommerce developer to resolve.
-
AuthorPosts
- You must be logged in to reply to this topic.