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

ShopifyMapper::get_mapped_categoriesprivateWC 1.0

Gets mapped WooCommerce product categories from Shopify collections.

Method of the class: ShopifyMapper{}

No Hooks.

Returns

Array. Mapped category data.

Usage

// private - for code of main (parent) class only
$result = $this->get_mapped_categories( $shopify_product ): array;
$shopify_product(object) (required)
The Shopify product data.

ShopifyMapper::get_mapped_categories() code WC 10.8.1

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;
}