This code removes the same products from displaying when using 2 Product loops on the same page. In this case, we have a custom loop of products displaying before the single product and a related loop of products showing after the single product on the same page. The code removes any duplicates so only unique products are shown on the same page.
Click the following gallery to view the default loop on the left image which shows duplicate products and the image on the right, once the code is installed, which removes all products shown in the first loop from displaying in the 2nd loop.
![The 2nd Loop Contains Duplicate Products as 1st Loop](https://wpsites.net/wp-content/uploads/2022/05/wc-duplicate-products-loop-213x300.png)
![Duplicate Products From 1st Loop Removed From 2nd Loop](https://wpsites.net/wp-content/uploads/2022/05/woocommerce-remove-product-duplicates-213x300.png)
Demo Video
On request
Installation
There’s only 1 step :
Copy & paste the PHP code ( excluding the opening PHP tag ) from the functions.php file to the end of your child themes functions file or custom functionality plugin.
You must be logged in to post a comment.