Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Shopify

ShopifyMapper::get_mapped_categoriesprivateWC 1.0

Gets mapped WooCommerce product categories from Shopify collections.

Метод класса: ShopifyMapper{}

Хуков нет.

Возвращает

Массив. Mapped category data.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->get_mapped_categories( $shopify_product ): array;
$shopify_product(объект) (обязательный)
The Shopify product data.

Код ShopifyMapper::get_mapped_categories() WC 11.0.0

private function get_mapped_categories( object $shopify_product ): array {
	$categories = array();
	if ( ! property_exists( $shopify_product, 'collections' ) || empty( $shopify_product->collections->edges ) ) {
		return $categories;
	}

	foreach ( $shopify_product->collections->edges as $collection_edge ) {
		$collection_node = $collection_edge->node;
		$categories[]    = array(
			'name' => wc_clean( $collection_node->title ),
			'slug' => sanitize_title( $collection_node->handle ),
		);
	}

	return $categories;
}