wordpress - Display Random Product Link -


i need php-code wordpress (woocommerce) display random product link.

for example, have product1 , want display on page (in description of product):

"see other products: [product2 - link] , [product3 - link]"

don't know how, need php code insert in post/pages/products , everywhere want on site.

i'm not coder , found code, example, display page title link, it's not need

<?php echo '<a href="'.get_permalink($product_id).'">'.get_the_title($product_id).'</a>'; ?> 

but how random product, don't know, help.

try :

 $args = array(     'posts_per_page'   => 1,     'orderby'          => 'rand',     'post_type'        => 'product' );   $random_products = get_posts( $args ); foreach ( $random_products $post ) : setup_postdata( $post ); ?>         <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php endforeach;  wp_reset_postdata(); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -