make sure attributes get a prefix
This commit is contained in:
parent
c89f2396ae
commit
a6a420bc40
|
@ -308,10 +308,20 @@ class WC_Product_Variation extends WC_Product_Simple {
|
|||
/**
|
||||
* Set attributes. Unlike the parent product which uses terms, variations are assigned
|
||||
* specific attributes using name value pairs.
|
||||
* @param array
|
||||
* @param array $raw_attributes
|
||||
*/
|
||||
public function set_attributes( $attributes ) {
|
||||
$this->set_prop( 'attributes', (array) $attributes );
|
||||
public function set_attributes( $raw_attributes ) {
|
||||
$raw_attributes = (array) $raw_attributes;
|
||||
$attributes = array();
|
||||
|
||||
foreach ( $raw_attributes as $key => $value ) {
|
||||
// Add attribute prefix which meta gets stored with.
|
||||
if ( 0 !== strpos( $key, 'attribute_' ) ) {
|
||||
$key = 'attribute_' . $key;
|
||||
}
|
||||
$attributes[ $key ] = $value;
|
||||
}
|
||||
$this->set_prop( 'attributes', $attributes );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -222,8 +222,8 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl
|
|||
$attributes = $product->get_attributes();
|
||||
$updated_attribute_keys = array();
|
||||
foreach ( $attributes as $key => $value ) {
|
||||
update_post_meta( $product->get_id(), 'attribute_' . $key, $value );
|
||||
$updated_attribute_keys[] = 'attribute_' . $key;
|
||||
update_post_meta( $product->get_id(), $key, $value );
|
||||
$updated_attribute_keys[] = $key;
|
||||
}
|
||||
|
||||
// Remove old taxonomies attributes so data is kept up to date - first get attribute key names.
|
||||
|
|
Loading…
Reference in New Issue