WordPress Codesnippets

woocommerce get all products on sale


// Your loop code
} else {
echo ‘No products found’;

This code queries the WordPress database for products, setting the post type to ‘product’, the number of posts per page to -1 (all posts), the post status to ‘publish’, and the meta query parameter to look for either a sale price greater than 0 or a minimum variation sale price greater than 0. If products are found, a loop is run over them for further processing. If no products are found, a message is displayed. Finally, the post data is reset.

Was this code snippet helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmatically save post

This code creates a WordPress post with the values of the ‘post_title’ and ‘post_content’ variables. It sets the post status to ‘publish’ and the author

Read More »

Create order programmatically

This code creates a new post in the WordPress database with post type ‘shop_order’, post title ‘Order #12345’, post status ‘wc-processing’, and ping status ‘closed’.

Read More »