Fix attribute matching in get_attribute_taxonomy_name

This commit is contained in:
Mike Jolley 2019-04-24 12:05:44 +01:00
parent f20a48b1e4
commit 76f0c015dd
1 changed files with 11 additions and 3 deletions

View File

@ -457,13 +457,21 @@ class WC_REST_Products_V2_Controller extends WC_REST_Legacy_Products_Controller
* @return string
*/
protected function get_attribute_taxonomy_name( $slug, $product ) {
// Format slug so it matches attributes of the product.
$slug = wc_attribute_taxonomy_slug( $slug );
$attributes = $product->get_attributes();
$attribute = false;
if ( ! isset( $attributes[ $slug ] ) ) {
return wc_attribute_taxonomy_slug( $slug );
// pa_ attributes.
if ( isset( $attributes[ wc_attribute_taxonomy_name( $slug ) ] ) ) {
$attribute = $attributes[ wc_attribute_taxonomy_name( $slug ) ];
} elseif ( isset( $attributes[ $slug ] ) ) {
$attribute = $attributes[ $slug ];
}
$attribute = $attributes[ $slug ];
if ( ! $attribute ) {
return $slug;
}
// Taxonomy attribute name.
if ( $attribute->is_taxonomy() ) {