Automattic\WooCommerce\Blocks\BlockTypes
AbstractProductGrid::set_stock_status_query_args()
Set which stock status to use when displaying products.
Method of the class: AbstractProductGrid{}
No Hooks.
Return
null
. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->set_stock_status_query_args( $query_args );
- $query_args(array) (required) (passed by reference — &)
- Query args.
AbstractProductGrid::set_stock_status_query_args() AbstractProductGrid::set stock status query args code WC 9.4.2
protected function set_stock_status_query_args( &$query_args ) { $stock_statuses = array_keys( wc_get_product_stock_status_options() ); // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query if ( isset( $this->attributes['stockStatus'] ) && $stock_statuses !== $this->attributes['stockStatus'] ) { // Reset meta_query then update with our stock status. $query_args['meta_query'] = $this->meta_query; $query_args['meta_query'][] = array( 'key' => '_stock_status', 'value' => array_merge( [ '' ], $this->attributes['stockStatus'] ), 'compare' => 'IN', ); } else { $query_args['meta_query'] = $this->meta_query; } // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_query }