WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Show sale items in query (2 posts)

  1. zerodegreeburn
    Member
    Posted 7 months ago #

    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/

  2. akherati
    Member
    Posted 1 month ago #

    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
    طراحی قالب وردپرس

Reply

You must log in to post.

About this Plugin

About this Topic