M
M
Mozzarella2018-04-15 13:50:02
SQL
Mozzarella, 2018-04-15 13:50:02

How to get max price of all products in woocommerce?

I use this code

global $wpdb;
    $minsql = "SELECT MIN(meta_value) FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value<>0 AND meta_value IS NOT NULL";
    $maxsql = "SELECT MAX(meta_value) FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value<>0 AND meta_value IS NOT NULL";
    $minPrice = $wpdb->get_var($wpdb->prepare($minsql, '_price'));
    $maxPrice = $wpdb->get_var($wpdb->prepare($maxsql, '_price'));

But it returns something wrong, for some reason not from all products

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question