WC_Product_Variation_Data_Store_CPT::generate_product_title()
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{}
Hooks from the method
Return
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() WC Product Variation Data Store CPT::generate product title code WC 9.8.2
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 ); }