Instyle - Woocommerce: Display only discounted/sale products

eCommerce WordPress theme to create online shop with WooCommerce support
GK User
Sun Nov 06, 2016 11:26 pm
Hi, I would like some help!

I am trying to only show discounted products on my page with Instyle and woocommerce. I have tried to make changes to the woocommerce "class-wc-query.php", as explained here: https://www.kathyisawesome.com/woocomme ... uct-query/, but it does not do the trick. I suspect the Instyle theme is overriding my code, or isn't it triggered?

I know that the $product_ids_on_sale works since i got badges on the sale-items. This is what I have changed in the "class-wc-query.php":
Code: Select all
/**
  * Hook into pre_get_posts to do the main product query.
  * @access public
  * @param mixed $q query object
  * @return void
  */
 public function pre_get_posts( $q ) {
  if ( ! $q->is_main_query() ) {
  $product_ids_on_sale    = wc_get_product_ids_on_sale();
  $q->set( 'post__in', (array) $product_ids_on_sale );
  }

My web-page: http://www.fersketilbud.no/

Any help?
User avatar
Fresh Boarder

Joshua M
Mon Nov 07, 2016 9:08 am
Hi,

There's no need to modify the query, you can use WooCommerce shortcode to display "on sale" products:
https://docs.woocommerce.com/document/w ... section-15
User avatar
Moderator


cron
Remember me
Register New Account
If you are old Gavick user, click HERE for steps to retrieve your account.