Automattic\WooCommerce\Blocks\BlockTypes
FeaturedProduct::render_attributes
Renders the featured product attributes.
Method of the class: FeaturedProduct{}
No Hooks.
Returns
String.
Usage
// protected - for code of main (parent) or child class $result = $this->render_attributes( $product, $attributes );
- $product(WC_Product) (required)
- Product object.
- $attributes(array) (required)
- Block attributes.
Default:empty array
FeaturedProduct::render_attributes() FeaturedProduct::render attributes code WC 10.8.1
protected function render_attributes( $product, $attributes ) {
$output = '';
// Backwards compatibility: Only render legacy attributes if `editMode` exists as boolean value
// This allows us to distinguish between old and new version of the block (which accept inner blocks).
if ( array_key_exists( 'editMode', $attributes ) && is_bool( $attributes['editMode'] ) ) {
$legacy_title = sprintf(
'<h2 class="wc-block-featured-product__title">%s</h2>',
wp_kses_post( $product->get_title() )
);
if ( $product->is_type( ProductType::VARIATION ) ) {
$legacy_title .= sprintf(
'<h3 class="wc-block-featured-product__variation">%s</h3>',
wp_kses_post( wc_get_formatted_variation( $product, true, true, false ) )
);
}
$output .= $legacy_title;
if (
! isset( $attributes['showDesc'] ) ||
( isset( $attributes['showDesc'] ) && false !== $attributes['showDesc'] )
) {
$desc_str = sprintf(
'<div class="wc-block-featured-product__description">%s</div>',
wc_format_content( wp_kses_post( $product->get_short_description() ? $product->get_short_description() : wc_trim_string( $product->get_description(), 400 ) ) )
);
$output .= $desc_str;
}
if (
! isset( $attributes['showPrice'] ) ||
( isset( $attributes['showPrice'] ) && false !== $attributes['showPrice'] )
) {
$price_str = sprintf(
'<div class="wc-block-featured-product__price">%s</div>',
wp_kses_post( $product->get_price_html() )
);
$output .= $price_str;
}
}
return $output;
}