S
S
smash_wp2015-10-06 12:44:00
Online shopping
smash_wp, 2015-10-06 12:44:00

How to display only promotional products in WooCommerce?

How to display only those products for which there is a promotion?
That is, such goods, which, in addition to the base price, have a sale price.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2015-10-06
@smash_wp

so wp-panda.com/woocommerce_posts/woocommerce-shortco...
loop is much simpler

<ul class="products">
  <?php
                $product_ids_on_sale = wc_get_product_ids_on_sale();

    $args = array(
      'post_type' => 'product',
                        'post__in' => array_merge( array( 0 ), $product_ids_on_sale )
      );
    $loop = new WP_Query( $args );
    if ( $loop->have_posts() ) {
      while ( $loop->have_posts() ) : $loop->the_post();
        wc_get_template_part( 'content', 'product' );
      endwhile;
    } else {
      echo __( 'Продуктов не найдено' );
    }
    wp_reset_postdata();
  ?>
</ul><!--/.products-->

C
CrewCut, 2015-10-06
@CrewCut

You can use the shortcode [sale_products per_page="12"] (12 - the number of products per output)
You can use the code:

$args = array(
    'post_type'      => 'product',
    'meta_query'     => array(
        'relation' => 'OR',
        array( // Simple products type
            'key'           => '_sale_price',
            'value'         => 0,
            'compare'       => '>',
            'type'          => 'numeric'
        ),
        array( // Variable products type
            'key'           => '_min_variation_sale_price',
            'value'         => 0,
            'compare'       => '>',
            'type'          => 'numeric'
        )
    )
);

query_posts( $args );

Find out if there is a discount:
--
Depending on what you need in a particular case

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question