Hide price for sold out products in WooCommerce

add_filter( 'woocommerce_get_price_html', 'wpcb_hide_price_on_sold_out', PHP_INT_MAX, 2 );
if ( ! function_exists( 'wpcb_hide_price_on_sold_out' ) ) {
	/**
	 * wpcb_hide_price_on_sold_out.
	 *
	 * @see https://wpcodebook.com/snippets/hide-price-for-sold-out-products-in-woocommerce/
	 */
	function wpcb_hide_price_on_sold_out( $price_html, $product ) {
		return ( ! $product->is_in_stock() ? '' : $price_html );
	}
}

Fix "out of stock" products count on archives in WooCommerce

/**
 * fix_hide_out_of_stock_products.
 */
add_action( 'pre_get_posts', 'fix_hide_out_of_stock_products' );
function fix_hide_out_of_stock_products( $q ) {
	if ( ! $q->is_main_query() || is_admin() || ! $q->is_archive() ) {
		return;
	}
	$meta_query   = ( array ) $q->get( 'meta_query' );
	$meta_query[] = array(
		'key'       => '_stock_status',
		'value'     => 'outofstock',
		'compare'   => 'NOT IN'
	);
	$q->set( 'meta_query', $meta_query );
	remove_action( 'pre_get_posts', 'fix_hide_out_of_stock_products' );
}