From 7620473fa5fbc9b0a960aa667e373fb84f00bee8 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 11 Aug 2017 13:52:28 +0100 Subject: [PATCH] Support callback for index --- includes/wc-core-functions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index e0d8a59a714..096ec27881e 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -1650,7 +1650,10 @@ function wc_list_pluck( $list, $callback_or_field, $index_key = null ) { */ $newlist = array(); foreach ( $list as $value ) { - if ( isset( $value->$index_key ) ) { + // Get index. @since 3.2.0 this supports a callback. + if ( is_callable( array( $value, $index_key ) ) ) { + $newlist[ $value->{$index_key}() ] = $value->{$callback_or_field}(); + } elseif ( isset( $value->$index_key ) ) { $newlist[ $value->$index_key ] = $value->{$callback_or_field}(); } else { $newlist[] = $value->{$callback_or_field}();