Automattic\WooCommerce\Blocks\Patterns

PTKPatternsStore::map_categoriesprivateWC 1.0

Change the categories of the patterns to match the ones used in the CYS flow

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

Хуков нет.

Возвращает

Массив. The patterns with the categories mapped.

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

// private - только в коде основоного (родительского) класса
$result = $this->map_categories( $patterns );
$patterns(массив) (обязательный)
The patterns to map categories for.

Код PTKPatternsStore::map_categories() WC 9.9.5

private function map_categories( array $patterns ) {
	return array_map(
		function ( $pattern ) {
			if ( isset( $pattern['categories'] ) ) {
				foreach ( $pattern['categories'] as $key => $category ) {
					if ( isset( $category['slug'] ) && isset( self::CATEGORY_MAPPING[ $key ] ) ) {
						$new_category = self::CATEGORY_MAPPING[ $key ];
						unset( $pattern['categories'][ $key ] );
						$pattern['categories'][ $new_category ]['slug']  = $new_category;
						$pattern['categories'][ $new_category ]['title'] = ucfirst( $new_category );
					}
				}
			}

			return $pattern;
		},
		$patterns
	);
}