Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks
Product_Price::build_grouped_product_price
Build price HTML for grouped products.
Method of the class: Product_Price{}
No Hooks.
Returns
String.
Usage
// private - for code of main (parent) class only $result = $this->build_grouped_product_price( $product ): string;
- $product(WC_Product_Grouped) (required)
- Grouped product object.
Product_Price::build_grouped_product_price() Product Price::build grouped product price code WC 10.5.0
private function build_grouped_product_price( \WC_Product_Grouped $product ): string {
$children = $product->get_children();
if ( empty( $children ) ) {
return '';
}
$prices = array();
foreach ( $children as $child_id ) {
$child = wc_get_product( $child_id );
if ( $child && $child->get_price() !== '' ) {
$prices[] = wc_get_price_to_display( $child, array( 'price' => (float) $child->get_price() ) );
}
}
if ( empty( $prices ) ) {
return '';
}
$min_price = min( $prices );
$max_price = max( $prices );
return sprintf(
'<span>%s — %s</span>',
wc_price( (float) $min_price, array( 'in_span' => false ) ),
wc_price( (float) $max_price, array( 'in_span' => false ) )
);
}