WC_Product_Variation_Data_Store_CPT::generate_product_title │ protected │ WC 3.0.0

Generates a title with attribute information for a variation. Products will get a title of the form "Name - Value, Value" or just "Name".

Method of the class: WC_Product_Variation_Data_Store_CPT{}

Returns

string.

Usage

// protected - for code of main (parent) or child class
$result = $this->generate_product_title( $product );
$product(WC_Product) (required)
Product object.

Changelog

Since 3.0.0 Introduced.

WC_Product_Variation_Data_Store_CPT::generate_product_title() code WC 11.2.1

protected function generate_product_title( $product ) {
	$should_include_attributes = $this->should_include_attributes_in_title( $product );

	/**
	 * Filters the separator used between a variation product title and its attributes.
	 *
	 * @since 3.0.2
	 * @param string     $separator Separator between the product title and attributes.
	 * @param WC_Product $product Variation product object.
	 */
	$separator    = apply_filters( 'woocommerce_product_variation_title_attributes_separator', ' - ', $product );
	$title_base   = get_post_field( 'post_title', $product->get_parent_id() );
	$title_suffix = $should_include_attributes ? wc_get_formatted_variation( $product, true, false ) : '';

	/**
	 * Filters the generated variation product title.
	 *
	 * @since 3.0.0
	 * @param string     $title Generated variation title.
	 * @param WC_Product $product Variation product object.
	 * @param string     $title_base Parent product title.
	 * @param string     $title_suffix Formatted attribute values, or an empty string.
	 */
	return apply_filters( 'woocommerce_product_variation_title', $title_suffix ? $title_base . $separator . $title_suffix : $title_base, $product, $title_base, $title_suffix );
}