This code displays a custom loop of products which haven’t sold in the last x months. In this case, the last 3 months.
- Objective: Display products that haven’t been sold in the last 3 months.
-
Process:
- Calculate the date 3 months ago from today’s date.
- Query products from the database.
- Filter products based on specific conditions.
- Display the filtered products.
-
Filter Conditions:
- Include products with zero sales.
- Include products with a sale end date before the last 3 months.
Video Demo
Shows products added to cart and sold which are then removed from the custom loop which only shows sold products within a set date range.
Installation
There’s only 1 step : Copy and paste the code to the end of your child themes functions file or custom PHP code snippets field/plugin.
Settings
Line 16, modify this value to anything you like :
-3 months