| @@ -231,9 +231,8 @@ | ||
| 231 | 231 | 'limit' => $limit, |
| 232 | 232 | 'orderby' => 'date', |
| 233 | 233 | 'order' => 'DESC', |
| 234 | 234 | 'status' => 'any', |
| 235 | - 'return' => 'ids', | |
| 236 | 235 | ) |
| 237 | 236 | ); |
| 238 | 237 | if ( ! \is_array( $orders ) || empty( $orders ) ) { |
| 239 | 238 | return array(); |
| @@ -240,18 +239,16 @@ | ||
| 240 | 239 | } |
| 241 | 240 | |
| 242 | 241 | // Tally populated rows per candidate. |
| 243 | 242 | $counts = array_fill_keys( array_keys( $candidates ), 0 ); |
| 244 | - foreach ( $orders as $order_id ) { | |
| 245 | - if ( \is_object( $order_id ) && \method_exists( $order_id, 'get_id' ) ) { | |
| 246 | - $order_id = $order_id->get_id(); | |
| 247 | - } | |
| 248 | - $meta = \get_post_meta( (int) $order_id ); | |
| 249 | - if ( ! \is_array( $meta ) || empty( $meta ) ) { | |
| 243 | + foreach ( $orders as $order ) { | |
| 244 | + // Read meta through the order object: with HPOS on (and sync off) it lives | |
| 245 | + // in wc_orders_meta, where get_post_meta() finds nothing. | |
| 246 | + if ( ! \is_object( $order ) || ! \method_exists( $order, 'get_meta' ) ) { | |
| 250 | 247 | continue; |
| 251 | 248 | } |
| 252 | 249 | foreach ( $candidates as $meta_key => $_type ) { |
| 253 | - $value = isset( $meta[ $meta_key ][0] ) ? $meta[ $meta_key ][0] : null; | |
| 250 | + $value = $order->get_meta( $meta_key ); | |
| 254 | 251 | if ( '' === $value || array() === $value || null === $value ) { |
| 255 | 252 | continue; |
| 256 | 253 | } |
| 257 | 254 | ++$counts[ $meta_key ]; |