I have created a little php file that will display a list of products that "Customers have also bought" that I want to display on each of my products pages. However, I want to exclude the same product showing up as an "also bought" on the product page.
Here is the php file I have created that loads a random product on page load:
THIS FILE IS CALLED "**products.php**"
<?php
// Customers also bought
$product1 = '<a href="../images/image1.jpg" class="zoom">
<img src="../images/image1.jpg" alt="gallery-image" title="gallery-image" class="img-responsive" /></a>
<div class="item-hover"><a href="../product1.php">Product 1</a> </div>';
$product2 = '<a href="../images/image2.jpg" class="zoom">
<img src="../images/image2.jpg" alt="gallery-image" title="gallery-image" class="img-responsive" /></a>
<div class="item-hover"><a href="../product2.php">Product 2</a> </div>';
$product3 = '<a href="../images/image3.jpg" class="zoom">
<img src="../images/image3.jpg" alt="gallery-image" title="gallery-image" class="img-responsive" /></a>
<div class="item-hover"><a href="../product3.php">Product 3</a> </div>';
$product4 = '<a href="../images/image4.jpg" class="zoom">
<img src="../images/image4.jpg" alt="gallery-image" title="gallery-image" class="img-responsive" /></a>
<div class="item-hover"><a href="../product4.php">Product 4</a> </div>';
$product5 = '<a href="../images/image1.jpg" class="zoom">
<img src="../images/image5.jpg" alt="gallery-image" title="gallery-image" class="img-responsive" /></a>
<div class="item-hover"><a href="../product5.php">Product 5</a> </div>';
$products = array($product1, $product2, $product3, $product4, $product5);
shuffle($products);
?>
Here is the code I am using in my main product pages:
This file is called **product1.php**
<?php
include("../includes/**products.php**");
?>
<h4>Customers Also Bought</h4>
<div class="col-lg-6 col-md-6 col-xs-6 gallery-item gallery-popup all themes">
<figure> <?php print $products[0] ?> </figure>
</div>