CCCPaste

JKIT || Hide Out of Stock Items

/**
 * JKIt Hide Out of Stock Items
 *
 * Hide Out of Stock Product in Jeg Elementor Kit Query's
 * Executed if is Jeg Elementor Kit Query and Post Type is Product (WooCommerce)
 *
 * @param array $args \WP_Query Arguments.
 * @param array $attr Attribute.
 */
function jkit_hide_out_of_stock_items( $args, $attr ) {
	if ( isset( $attr['post_type'] ) && 'product' === $attr['post_type'] ) {
		$args['meta_key']     = '_stock_status';
		$args['meta_value']   = 'outofstock';
		$args['meta_compare'] = '!=';
	}

	return $args;
}
add_filter( 'jeg_default_query_args', 'jkit_hide_out_of_stock_items', 10, 2 );