[Support request] "Previous" and "Next" buttons in Woocommerce

Home Forums Support [Support request] "Previous" and "Next" buttons in Woocommerce

Home Forums Support "Previous" and "Next" buttons in Woocommerce

Viewing 11 posts - 16 through 26 (of 26 total)
  • Author
    Posts
  • #638806
    Tom
    Lead Developer
    Lead 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', '&larr; Previous', true, false, 'product_cat' );
            previous_post_link( '%link', 'Next &rarr;', true, false, 'product_cat' );
        echo '</div>';
    }

    And it worked: http://prntscr.com/kdwujr

    I wonder if you have a plugin that’s conflicting?

    #639422
    Alberto

    Tom.

    I am adding the code through the Code Snippets plugin.

    I do not know how you are adding your …

    #639429
    David
    Staff
    Customer Support

    Hi 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……

    #639433
    Alberto

    David.

    I inform you that I have disabled the plugin YITH WooCommerce Category Accordion and the arrows still do not appear …

    #639438
    David
    Staff
    Customer Support

    Can you work through each of the plugins? Probably best to disable any caches you may have whilst testing.

    #1354177
    Simon

    Hi 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.

    #1354493
    Tom
    Lead Developer
    Lead Developer

    That 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!

    #1429574
    Katharine

    Hello,

    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,
    Katie

    #1429889
    Tom
    Lead Developer
    Lead Developer

    A new ticket would be great, especially if you could link us to your site ๐Ÿ™‚

    Thanks!

    #2379808
    Kenny Williamson

    Hello 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).

    #2379896
    David
    Staff
    Customer Support

    Hi 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.

Viewing 11 posts - 16 through 26 (of 26 total)
  • You must be logged in to reply to this topic.