Merge pull request #23451 from woocommerce/fix/23387

Array handling in `get_catalog_ordering_args` to prevent notices
This commit is contained in:
Mike Jolley 2019-04-24 14:52:47 +01:00 committed by GitHub
commit 2810e6cdf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -454,8 +454,9 @@ class WC_Query {
$order = ! empty( $orderby_value[1] ) ? $orderby_value[1] : $order;
}
$orderby = strtolower( $orderby );
$order = strtoupper( $order );
// Convert to correct format.
$orderby = strtolower( is_array( $orderby ) ? (string) current( $orderby ) : (string) $orderby );
$order = strtoupper( is_array( $order ) ? (string) current( $order ) : (string) $order );
$args = array(
'orderby' => $orderby,
'order' => ( 'DESC' === $order ) ? 'DESC' : 'ASC',

View File

@ -282,6 +282,20 @@ class WC_Tests_WC_Query extends WC_Unit_Test_Case {
'meta_key' => '',
),
),
array(
'orderby' => array(
'price',
'date',
),
'order' => array(
'DESC',
),
'expected' => array(
'orderby' => 'price',
'order' => 'DESC',
'meta_key' => '',
),
),
);
foreach ( $data as $test ) {