WC_API_Products::get_variation_data()privateWC 2.1

Get an individual variation's data.

Method of the class: WC_API_Products{}

No Hooks.

Return

Array.

Usage

// private - for code of main (parent) class only
$result = $this->get_variation_data( $product );
$product(WC_Product) (required)
-

Changelog

Since 2.1 Introduced.

WC_API_Products::get_variation_data() code WC 8.9.0

private function get_variation_data( $product ) {
	$variations = array();

	foreach ( $product->get_children() as $child_id ) {
		$variation = wc_get_product( $child_id );

		if ( ! $variation || ! $variation->exists() ) {
			continue;
		}

		$variations[] = array(
			'id'                 => $variation->get_id(),
			'created_at'         => $this->server->format_datetime( $variation->get_date_created(), false, true ),
			'updated_at'         => $this->server->format_datetime( $variation->get_date_modified(), false, true ),
			'downloadable'       => $variation->is_downloadable(),
			'virtual'            => $variation->is_virtual(),
			'permalink'          => $variation->get_permalink(),
			'sku'                => $variation->get_sku(),
			'price'              => $variation->get_price(),
			'regular_price'      => $variation->get_regular_price(),
			'sale_price'         => $variation->get_sale_price() ? $variation->get_sale_price() : null,
			'taxable'            => $variation->is_taxable(),
			'tax_status'         => $variation->get_tax_status(),
			'tax_class'          => $variation->get_tax_class(),
			'managing_stock'     => $variation->managing_stock(),
			'stock_quantity'     => $variation->get_stock_quantity(),
			'in_stock'           => $variation->is_in_stock(),
			'backorders_allowed' => $variation->backorders_allowed(),
			'backordered'        => $variation->is_on_backorder(),
			'purchaseable'       => $variation->is_purchasable(),
			'visible'            => $variation->variation_is_visible(),
			'on_sale'            => $variation->is_on_sale(),
			'weight'             => $variation->get_weight() ? $variation->get_weight() : null,
			'dimensions'         => array(
				'length' => $variation->get_length(),
				'width'  => $variation->get_width(),
				'height' => $variation->get_height(),
				'unit'   => get_option( 'woocommerce_dimension_unit' ),
			),
			'shipping_class'    => $variation->get_shipping_class(),
			'shipping_class_id' => ( 0 !== $variation->get_shipping_class_id() ) ? $variation->get_shipping_class_id() : null,
			'image'             => $this->get_images( $variation ),
			'attributes'        => $this->get_attributes( $variation ),
			'downloads'         => $this->get_downloads( $variation ),
			'download_limit'    => (int) $product->get_download_limit(),
			'download_expiry'   => (int) $product->get_download_expiry(),
		);
	}

	return $variations;
}