Better fallback for ajax variations in case sync_attributes has ran

This commit is contained in:
Mike Jolley 2015-09-14 16:50:58 +01:00
parent 8e19abe368
commit 3dbe9ccd95
1 changed files with 8 additions and 7 deletions

View File

@ -504,13 +504,6 @@ class WC_Product_Variable extends WC_Product {
$value = wc_clean( $match_attributes[ $attribute_field_name ] );
/**
* Pre 2.4 handling where 'slugs' were saved instead of the full text attribute.
*/
if ( version_compare( get_post_meta( $this->id, '_product_version', true ), '2.4.0', '<' ) ) {
$value = sanitize_title( $value );
}
$query_args['meta_query'][] = array(
'key' => $attribute_field_name,
'value' => array( '', $value ),
@ -522,6 +515,14 @@ class WC_Product_Variable extends WC_Product {
if ( $matches && ! is_wp_error( $matches ) ) {
return current( $matches );
/**
* Pre 2.4 handling where 'slugs' were saved instead of the full text attribute.
* Fallback is here because there are cases where data will be 'synced' but the product version will remain the same. @see WC_Product_Variable::sync_attributes
*/
} elseif ( version_compare( get_post_meta( $this->id, '_product_version', true ), '2.4.0', '<' ) ) {
return $match_attributes === array_map( 'sanitize_title', $match_attributes ) ? 0 : $this->get_matching_variation( array_map( 'sanitize_title', $match_attributes ) );
} else {
return 0;
}