function misha_hide_out_of_stock_option( $option ){ return 'yes'; } add_action( 'woocommerce_before_template_part', function( $template_name ) { if( 'single-product/related.php' !== $template_name ) { return; } add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', 'misha_hide_out_of_stock_option' ); } ); add_action( 'woocommerce_after_template_part', function( $template_name ) { if( 'single-product/related.php' !== $template_name ) { return; } remove_filter( 'pre_option_woocommerce_hide_out_of_stock_items', 'misha_hide_out_of_stock_option' ); } );
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter