Get product min_price by sku

Question

I need to get the smallest value of min_price by sku for product post_type and draft post_status.

    function get_product_min_price_by_sku( $sku ) {
        global $wpdb;

        $min_price = $wpdb->get_var(
            $wpdb->prepare(
                "
                SELECT
                MIN(min_price) 
                FROM {$wpdb->wc_product_meta_lookup} 
                WHERE
                sku='$sku'              
                "
            )
        );
        return $min_price;
    }

How can I add the post status condition to this function?

AND posts.post_status = 'draft'

BTW. I allow multiple products with same sku:

add_filter( 'wc_product_has_unique_sku', '__return_false', PHP_INT_MAX );
0
, , antonimac 2 years 2019-10-27T15:09:51-05:00 0 Answers 76 views 0

Leave an answer

Browse
Browse