Automattic\WooCommerce\Internal\StockNotifications

Notification::get_variation_attributes_with_posted_data │ private │ WC 1.0

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.

Method of the class: Notification{}

No Hooks.

Returns

array.

Usage

// private - for code of main (parent) class only
$result = $this->get_variation_attributes_with_posted_data( $product ): array;
$product(WC_Product_Variation) (required)
The notification's variation.

Notification::get_variation_attributes_with_posted_data() code 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 ) );
}