I\'ve read this: Woocommerce get next / previous product
and also tried this:
Example:
Explanation:
Using WordPress' previous_post_link
or next_post_link
will work. In fact, you're almost there.
In addition to setting true
as the third parameter ($in_same_term), make sure to also pass in the taxonomy name as the last parameter ($taxonomy). For WooCommerce, the default product category is product_cat
.
One thing to note, these functions will get next/previous products that match any terms assigned to the current product. Terms can be excluded by passing the term id(s) as the fourth parameter ($exclude_terms).
Reference:
https://developer.wordpress.org/reference/functions/previous_post_link/ https://developer.wordpress.org/reference/functions/next_post_link/