| @@ -231,8 +231,9 @@ | ||
| 231 | 231 | 'limit' => $limit, |
| 232 | 232 | 'orderby' => 'date', |
| 233 | 233 | 'order' => 'DESC', |
| 234 | 234 | 'status' => 'any', |
| 235 | + 'return' => 'ids', | |
| 235 | 236 | ) |
| 236 | 237 | ); |
| 237 | 238 | if ( ! \is_array( $orders ) || empty( $orders ) ) { |
| 238 | 239 | return array(); |
| @@ -239,16 +240,18 @@ | ||
| 239 | 240 | } |
| 240 | 241 | |
| 241 | 242 | // Tally populated rows per candidate. |
| 242 | 243 | $counts = array_fill_keys( array_keys( $candidates ), 0 ); |
| 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' ) ) { | |
| 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 ) ) { | |
| 247 | 250 | continue; |
| 248 | 251 | } |
| 249 | 252 | foreach ( $candidates as $meta_key => $_type ) { |
| 250 | - $value = $order->get_meta( $meta_key ); | |
| 253 | + $value = isset( $meta[ $meta_key ][0] ) ? $meta[ $meta_key ][0] : null; | |
| 251 | 254 | if ( '' === $value || array() === $value || null === $value ) { |
| 252 | 255 | continue; |
| 253 | 256 | } |
| 254 | 257 | ++$counts[ $meta_key ]; |