WordPress.org

Support

Support » Plugins and Hacks » Show sale items in query

Show sale items in query

  • Hi,

    I’d like to modify pre_get_posts so that I can show sale items if ?sale=1 is present in the URL.

    I found the following code from another site, and this works well:

    $meta_query = array(
    
    	            array(
    	                'key' => '_sale_price',
    	                'value' => 0,
    	                'compare' => '>',
    	                'type' => 'numeric'
    	            )
    	         );

    However this returns products who are *scheduled* to go on sale. How do I check to ensure I don’t include those products that aren’t also scheduled to go on sale in the future.

    Thanks

    https://wordpress.org/plugins/woocommerce/

Viewing 1 replies (of 1 total)
  • hi
    try this code:

    $meta_query = array(
    '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'
    	)
    	)
    );

    good luck
    طراحی قالب وردپرس

Viewing 1 replies (of 1 total)
  • The topic ‘Show sale items in query’ is closed to new replies.