Automattic\WooCommerce\Blocks\BlockTypes

ProductSummary::get_sourceprivateWC 1.0

Get product description depends on config.

Method of the class: ProductSummary{}

No Hooks.

Returns

String.

Usage

// private - for code of main (parent) class only
$result = $this->get_source( $product, $show_description_if_empty );
$product(WC_Product) (required)
Product object.
$show_description_if_empty(true|false) (required)
Defines if fallback to full description.

ProductSummary::get_source() code WC 9.9.4

private function get_source( $product, $show_description_if_empty ) {
	$short_description = $product->get_short_description();

	if ( $short_description ) {
		// Logic copied from https://github.com/woocommerce/woocommerce/blob/637dde283057ed6667ff81c73ed08774552f631d/plugins/woocommerce/includes/wc-core-functions.php#L53-L62.
		$short_description = wp_kses_post( $short_description );
		$short_description = $GLOBALS['wp_embed']->run_shortcode( $short_description );
		$short_description = shortcode_unautop( $short_description );
		$short_description = do_shortcode( $short_description );
		return $short_description;
	}

	$description = $product->get_description();

	if ( $show_description_if_empty && $description ) {
		// Logic copied from https://github.com/woocommerce/woocommerce/blob/637dde283057ed6667ff81c73ed08774552f631d/plugins/woocommerce/includes/wc-core-functions.php#L53-L62.
		$description = wp_kses_post( $description );
		$description = $GLOBALS['wp_embed']->run_shortcode( $description );
		$description = shortcode_unautop( $description );
		$description = do_shortcode( $description );
		return $description;
	}

	return '';
}