Re-indexing `get_available_variations` method values when `woocommerce_available_variation` filter return false.

### All Submissions:

* [x] Have you followed the [WooCommerce Contributing guideline](https://github.com/woocommerce/woocommerce/blob/master/.github/CONTRIBUTING.md)?
* [x] Does your code follow the [WordPress' coding standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/)?
* [x] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change?

<!-- Mark completed items with an [x] -->

<!-- You can erase any parts of this template not applicable to your Pull Request. -->

### Changes proposed in this Pull Request:

Re-indexing `get_available_variations` method values.

Suppose you made changed with `woocommerce_available_variation` hook and skip returning some specific variation product with false value. There is `array_filter` function to filter empty values from `get_available_variations` but it keeps index which convert to js object rather then array on `single-product/add-to-cart/variable.php` template variation form `data-product_variations` attribute, and select box dropdown doesn't show. I just added `array_values` PHP function to reindex after `array_filter` function which convert to js array rather then js object before `get_available_variations` function return.

Closes # .

### How to test the changes in this Pull Request:

1. Before approving pull req just return false on a specific variation via `woocommerce_available_variation` filter.
2. Now check that variation product dropdown doesn't show. Because it needs to reindex array.

### Other information:

* [x] Have you added an explanation of what your changes do and why you'd like us to include them?
* [ ] Have you written new tests for your changes, as applicable?
* [x] Have you successfully ran tests with your changes locally?

<!-- Mark completed items with an [x] -->

### Changelog entry

> Enter a short summary of all changes on this Pull Request. This will appear in the changelog if accepted.
This commit is contained in:
Emran Ahmed 2018-07-20 20:14:57 +06:00 committed by GitHub
parent 33949f3c25
commit f0151ca873
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 4 deletions

View File

@ -300,11 +300,9 @@ class WC_Product_Variable extends WC_Product {
continue;
}
if( $this->get_available_variation( $variation ) ){
$available_variations[] = $this->get_available_variation( $variation );
}
$available_variations[] = $this->get_available_variation( $variation );
}
$available_variations = array_filter( $available_variations );
$available_variations = array_values( array_filter( $available_variations ) );
return $available_variations;
}