When syncing OLD products, update the attributes to 2.4 standard
This commit is contained in:
parent
f19ba7a755
commit
6626c68175
|
@ -628,6 +628,40 @@ class WC_Product_Variable extends WC_Product {
|
|||
// Loop the variations
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Pre 2.4 handling where 'slugs' were saved instead of the full text attribute.
|
||||
* Attempt to get full version of the text attribute from the parent and UPDATE meta.
|
||||
*/
|
||||
if ( version_compare( get_post_meta( $product_id, '_product_version', true ), '2.4.0', '<' ) ) {
|
||||
$parent_attributes = array_filter( (array) get_post_meta( $product_id, '_product_attributes', true ) );
|
||||
|
||||
foreach ( $children as $child_id ) {
|
||||
$all_meta = get_post_meta( $child_id );
|
||||
|
||||
foreach ( $all_meta as $name => $value ) {
|
||||
if ( 0 !== strpos( $name, 'attribute_' ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( sanitize_title( $value[0] ) === $value[0] ) {
|
||||
foreach ( $parent_attributes as $attribute ) {
|
||||
if ( $name !== 'attribute_' . sanitize_title( $attribute['name'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$text_attributes = wc_get_text_attributes( $attribute['value'] );
|
||||
|
||||
foreach ( $text_attributes as $text_attribute ) {
|
||||
if ( sanitize_title( $text_attribute ) === $value[0] ) {
|
||||
$value[0] = $text_attribute;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_post_meta( $child_id, $name, $value[0] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the variable product to be virtual/downloadable if all children are virtual/downloadable
|
||||
foreach ( array( '_downloadable', '_virtual' ) as $meta_key ) {
|
||||
$all_variations_yes = true;
|
||||
|
|
Loading…
Reference in New Issue