Merge pull request #15277 from woocommerce/fix/float-number-comparison

Support floats for the custom sort function
This commit is contained in:
Mike Jolley 2017-05-26 11:16:22 +01:00 committed by GitHub
commit 62bcca6cce
1 changed files with 4 additions and 3 deletions

View File

@ -151,12 +151,13 @@ function wc_get_product_terms( $product_id, $taxonomy, $args = array() ) {
* @return int
*/
function _wc_get_product_terms_name_num_usort_callback( $a, $b ) {
$a_name = (int) $a->name;
$b_name = (int) $b->name;
$a_name = (float) $a->name;
$b_name = (float) $b->name;
if ( $a_name === $b_name ) {
if ( abs( $a_name - $b_name ) < 0.001 ) {
return 0;
}
return ( $a_name < $b_name ) ? -1 : 1;
}