Automattic\WooCommerce\Blocks\BlockTypes
ProductFilterPrice::get_filtered_price
Retrieve the price filter data for current block.
Method of the class: ProductFilterPrice{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->get_filtered_price( $block );
- $block(WP_Block) (required)
- Block instance.
ProductFilterPrice::get_filtered_price() ProductFilterPrice::get filtered price code WC 10.8.1
private function get_filtered_price( $block ) {
if ( ! isset( $block->context['filterParams'] ) ) {
return array();
}
$query_vars = ProductCollectionUtils::get_query_vars( $block, 1 );
unset( $query_vars['min_price'], $query_vars['max_price'] );
if ( ! empty( $query_vars['meta_query'] ) ) {
// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
$query_vars['meta_query'] = ProductCollectionUtils::remove_query_array( $query_vars['meta_query'], 'key', '_price' );
}
if ( isset( $query_vars['taxonomy'] ) && false !== strpos( $query_vars['taxonomy'], 'pa_' ) ) {
unset(
$query_vars['taxonomy'],
$query_vars['term']
);
}
$container = wc_get_container();
$price_results = $container->get( FilterDataProvider::class )->with( $container->get( QueryClauses::class ) )->get_filtered_price( $query_vars );
return array(
'min_price' => intval( floor( floatval( $price_results['min_price'] ?? 0 ) ) ),
'max_price' => intval( ceil( floatval( $price_results['max_price'] ?? 0 ) ) ),
);
}