Automattic\WooCommerce\Blocks\BlockTypes

ProductFilterStockStatus::register_active_filters_data()publicWC 1.0

Register the active filters data.

Method of the class: ProductFilterStockStatus{}

No Hooks.

Return

Array. Active filters data.

Usage

$ProductFilterStockStatus = new ProductFilterStockStatus();
$ProductFilterStockStatus->register_active_filters_data( $data, $params );
$data(array) (required)
The active filters data.
$params(array) (required)
The query param parsed from the URL.

ProductFilterStockStatus::register_active_filters_data() code WC 9.4.2

public function register_active_filters_data( $data, $params ) {
	$stock_status_options = wc_get_product_stock_status_options();

	if ( empty( $params[ self::STOCK_STATUS_QUERY_VAR ] ) ) {
		return $data;
	}

	$active_stock_statuses = array_filter(
		explode( ',', $params[ self::STOCK_STATUS_QUERY_VAR ] )
	);

	if ( empty( $active_stock_statuses ) ) {
		return $data;
	}

	$action_namespace = $this->get_full_block_name();

	$active_stock_statuses = array_map(
		function ( $status ) use ( $stock_status_options, $action_namespace ) {
			return array(
				'title'      => $stock_status_options[ $status ],
				'attributes' => array(
					'data-wc-on--click' => "$action_namespace::actions.removeFilter",
					'data-wc-context'   => "$action_namespace::" . wp_json_encode( array( 'value' => $status ), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ),
				),
			);
		},
		$active_stock_statuses
	);

	$data['stock'] = array(
		'type'  => __( 'Stock Status', 'woocommerce' ),
		'items' => $active_stock_statuses,
	);

	return $data;
}