Hello @csnlima
I have found a snippet from the thread that you suggested and it works fine, but there is still one problem. If there are 6 products added in my Up Sell section and only one is out of stock randomly it will load this product on the single-product page and the space will be just blank. So by default i always want to show 4 products, but sometimes is showing just 3 because one of them is out of stock (showing it as blank white space). I would liket o show the other products that are added in my Up Sell section and always show 4 products.
Is there something that can be added to the following snippet that can do a check for that and if a product is out of stock not to show it as blank, but to load some of the other products added in the Upsell section.
The snippet that I used:
/**
* Temporarily enable hide out of stock items.
*
* @param string $template_name
* @param string $template_path
* @param bool $located
* @param array $args
*/
function iconic_enable_hide_out_of_stock_items( $template_name, $template_path, $located, $args ) {
if( $template_name !== "cart/cross-sells.php" AND $template_name !== "single-product/up-sells.php") {
return;
}
add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', function( $option ) { return "yes"; }, 10, 1 );
}
/**
* Temporarily disable hide out of stock items.
*
* @param string $template_name
* @param string $template_path
* @param bool $located
* @param array $args
*/
function iconic_disable_hide_out_of_stock_items( $template_name, $template_path, $located, $args ) {
if( $template_name !== "cart/cross-sells.php" AND $template_name !== "single-product/up-sells.php") {
return;
}
add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', function( $option ) { return "no"; }, 10, 1 );
}
add_action( 'woocommerce_before_template_part', 'iconic_enable_hide_out_of_stock_items', 10, 4 );
add_action( 'woocommerce_after_template_part', 'iconic_disable_hide_out_of_stock_items', 10, 4 );