Automattic\WooCommerce\Internal\StockNotifications
Notification::get_variation_attributes_with_posted_data
Get the variation's attributes, with the shopper's posted values filled in.
Posted values only fill the variation's "Any" attributes (empty values); the variation's fixed values always win. Keys that no longer belong to the variation (e.g. a removed attribute) are dropped.
Метод класса: Notification{}
Хуков нет.
Возвращает
array.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_variation_attributes_with_posted_data( $product ): array;
- $product(WC_Product_Variation) (обязательный)
- The notification's variation.
Код Notification::get_variation_attributes_with_posted_data() Notification::get variation attributes with posted data WC 11.3.0
private function get_variation_attributes_with_posted_data( \WC_Product_Variation $product ): array {
$variation_attributes = $product->get_variation_attributes();
$posted_attributes = $this->get_meta( 'posted_attributes' );
if ( empty( $posted_attributes ) || ! is_array( $posted_attributes ) ) {
return $variation_attributes;
}
$any_attributes = array_filter(
$variation_attributes,
static function ( $value ) {
return '' === $value;
}
);
return array_merge( $variation_attributes, array_intersect_key( $posted_attributes, $any_attributes ) );
}