How do I show variations sorted by quantity in stock? I can override or extend the WC_Product_Variable class, but this solution doesn't seem optimal. What other options are there?

1 Answer 1


You can use the woocommerce_get_children filter:

function wpse_filter_variations( $variations, $product, $false ) {
    // Do you sorting here

    return $variations;
add_filter( 'woocommerce_get_children', 'wpse_filter_variations', 10, 3 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.