WC_Product_Variation_Data_Store_CPT::generate_product_title()protectedWC 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".

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

Возвращает

Строку.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->generate_product_title( $product );
$product(WC_Product) (обязательный)
Product object.

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

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

Код WC_Product_Variation_Data_Store_CPT::generate_product_title() WC 8.6.1

protected function generate_product_title( $product ) {
	$attributes = (array) $product->get_attributes();

	// Do not include attributes if the product has 3+ attributes.
	$should_include_attributes = count( $attributes ) < 3;

	// Do not include attributes if an attribute name has 2+ words and the
	// product has multiple attributes.
	if ( $should_include_attributes && 1 < count( $attributes ) ) {
		foreach ( $attributes as $name => $value ) {
			if ( false !== strpos( $name, '-' ) ) {
				$should_include_attributes = false;
				break;
			}
		}
	}

	$should_include_attributes = apply_filters( 'woocommerce_product_variation_title_include_attributes', $should_include_attributes, $product );
	$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 ) : '';

	return apply_filters( 'woocommerce_product_variation_title', $title_suffix ? $title_base . $separator . $title_suffix : $title_base, $product, $title_base, $title_suffix );
}