I need PHP-code for WordPress (Woocommerce) to display random product link.
For example, I have Product1 and want to display on this page (in description of my product):
“See also other products: [Product2 – link] and [Product3 – link]”
Don’t know how, I just need php code to insert it in post/pages/products and everywhere I want on my site.
I’m not a coder and I found this code, for example, to display page title with link, but it’s not what I need
<?php
echo '<a href="'.get_permalink($product_id).'">'.get_the_title($product_id).'</a>';
?>
But how to get random product, don’t know, thanks for help.
Try this :
The Perfect solution for outputting a single random product which can be achieved using the following code.
Have tested the same for you. It worked. Lemme Know if the same worked for you too.