Automattic\WooCommerce\Internal\StockNotifications

Notification::get_product_formatted_variation_listpublicWC 1.0

Retrieves the formatted attributes of the product based on the notification's posted attributes.

Wrapper of the wc_get_formatted_variation function.

Method of the class: Notification{}

No Hooks.

Returns

String.

Usage

$Notification = new Notification();
$Notification->get_product_formatted_variation_list( $flat );
$flat(true|false)
Flatten the list.
Default: false

Notification::get_product_formatted_variation_list() code WC 10.3.6

public function get_product_formatted_variation_list( bool $flat = false ) {

	$product = $this->get_product();
	if ( ! $product || ! $product->is_type( array( 'variation' ) ) ) {
		return '';
	}

	// Replace list with custom data.
	$attributes = $this->get_meta( 'posted_attributes' );
	if ( ! $attributes ) {
		$attributes = $product->get_attributes();
	}

	if ( empty( $attributes ) ) {
		return '';
	}

	$attrs = array();
	foreach ( $attributes as $key => $value ) {

		if ( 0 === strpos( $key, 'attribute_pa_' ) ) {
			$attrs[ str_replace( 'attribute_', '', $key ) ] = $value;
		} else {
			// By pass converting global product attributes.
			$attrs[ wc_attribute_label( str_replace( 'attribute_', '', $key ), $product ) ] = $value;
		}
	}

	$formatted_variation_list = wc_get_formatted_variation( $attrs, $flat, true, true );

	return $formatted_variation_list;
}