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.

Return

true|false.

Usage

woocommerce_output_product_categories( $args );
$args(array)
Arguments.
Default: array()

Changelog

Since 3.3.1 Introduced.

woocommerce_output_product_categories() code WC 9.4.2

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