Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // get the number of products in the shop which are on sale
- // usage: We have [products_available] available!
- // code goes in functions.php for your child theme
- add_shortcode('products_available', 'products_available');
- function products_available() {
- $args = array(
- 'post_type' => 'product',
- 'posts_per_page' => -1,
- 'orderby' => '',
- 'order' => '',
- 'meta_query' => array(
- array(
- 'key' => '_stock_status',
- 'value' => 'instock',
- 'compare' => '='
- )
- )
- );
- $loop = new WP_Query( $args );
- $products = $loop->posts;
- wp_reset_postdata();
- return count($products);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement