Ecommerce Shopify WordPress Discussion

Hide all on sale products on WooCommerce archive pages

I'm trying to hide all sale products on a static wordpress site, where a WooCommerce Product widget is placed. Is there any way to achieve that? The reason behind it is, that i want 2 category pages for each brand. 1 Sale Products, 1 Regular Products. I tried following code but it didn't work: add_filter( 'woocommerce_product_query_meta_query', 'on_sale_products_not_in_archives', 10, 2 ); function on_sale_products_not_in_archives( $meta_query, $query ) { // For woocommerce shop pages if( is_shop() ){ $meta_query[] = array( 'key' => '_sale_price', 'value' => '', 'compare' => '=', ); } return $meta_query; }
You can use wc_get_product_ids_on_sale() core function in a product query, like: add_action( 'woocommerce_product_query', 'not_on_sale_products_product_query' ); function not_on_sale_products_product_query( $q ) { // On product archive pages only if ( is_shop() || is_product_category() || is_product_tag() ) { $q->set( 'post__not_in', array_merge( array( 0 ), wc_get_product_ids_on_sale() ) ); } } But for a products widget you should try to use instead: add_filter( 'woocommerce_products_widget_query_args', 'not_on_sale_products_widget_query_args' ); function not_on_sale_products_widget_query_args( $query_args ) { // On product archive pages only if ( is_shop() || is_product_category() || is_product_tag() ) { $query_args['post__not_in'] = array_merge( array( 0 ), wc_get_product_ids_on_sale() ); } return $query_args; } Code goes in functions.php file of your child theme (or in a plugin). It could work Related: Get WooCommerce onSale products on Archives

February 4, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.