WC_Abstract_Legacy_Product::sync_attributes() public WC 1.0
Sync the variable product's attributes with the variations.
{} Это метод класса: WC_Abstract_Legacy_Product{}
Хуков нет.
Возвращает
Null. Ничего.
Использование
$result = WC_Abstract_Legacy_Product::sync_attributes( $product, $children );
- $product (обязательный)
- -
- $children(true/false)
- -
Код WC_Abstract_Legacy_Product::sync_attributes() WC Abstract Legacy Product::sync attributes WC 5.0.0
public static function sync_attributes( $product, $children = false ) {
if ( ! is_a( $product, 'WC_Product' ) ) {
$product = wc_get_product( $product );
}
/**
* 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->get_id(), '_product_version', true ), '2.4.0', '<' ) ) {
$parent_attributes = array_filter( (array) get_post_meta( $product->get_id(), '_product_attributes', true ) );
if ( ! $children ) {
$children = $product->get_children( 'edit' );
}
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 ( 'attribute_' . sanitize_title( $attribute['name'] ) !== $name ) {
continue;
}
$text_attributes = wc_get_text_attributes( $attribute['value'] );
foreach ( $text_attributes as $text_attribute ) {
if ( sanitize_title( $text_attribute ) === $value[0] ) {
update_post_meta( $child_id, $name, $text_attribute );
break;
}
}
}
}
}
}
}
}