woocommerce_output_product_categories()WC 3.3.1

Display product sub categories as thumbnails.

This is a replacement for woocommerce_product_subcategories which also does some logic based on the loop. This function however just outputs when called.

Возвращает

true|false.

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

woocommerce_output_product_categories( $args );
$args(массив)
Arguments.
По умолчанию: array()

Список изменений

С версии 3.3.1 Введена.

Код woocommerce_output_product_categories() WC 8.7.0

function woocommerce_output_product_categories( $args = array() ) {
	$args = wp_parse_args(
		$args,
		array(
			'before'    => apply_filters( 'woocommerce_before_output_product_categories', '' ),
			'after'     => apply_filters( 'woocommerce_after_output_product_categories', '' ),
			'parent_id' => 0,
		)
	);

	$product_categories = woocommerce_get_product_subcategories( $args['parent_id'] );

	if ( ! $product_categories ) {
		return false;
	}

	// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
	echo $args['before'];

	foreach ( $product_categories as $category ) {
		wc_get_template(
			'content-product_cat.php',
			array(
				'category' => $category,
			)
		);
	}

	// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
	echo $args['after'];

	return true;
}