From f0151ca873efa2b333269d41c64959fd0cdd6393 Mon Sep 17 00:00:00 2001 From: Emran Ahmed Date: Fri, 20 Jul 2018 20:14:57 +0600 Subject: [PATCH] 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? ### 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? ### Changelog entry > Enter a short summary of all changes on this Pull Request. This will appear in the changelog if accepted. --- includes/class-wc-product-variable.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-product-variable.php b/includes/class-wc-product-variable.php index b3676e6b51c..e1f89edd5c5 100644 --- a/includes/class-wc-product-variable.php +++ b/includes/class-wc-product-variable.php @@ -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; }