• Resolved Anas Mohammad

    (@devloperanas)


    Hi, I am trying to exclude stock out product form related products. I found a solution that do the thing but it hide the stock out product and create the blank space. My objective is to show related post of 4 items excluding stock out product. Is there any way to solve the issue?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi, @devloperanas!

    What solution have you found and applied that isn’t working for you? Please link us to that so we don’t recommend the same ??

    Thanks!

    Thread Starter Anas Mohammad

    (@devloperanas)

    Hi Rynald0s,

    I have used the blow code :

    `function iconic_enable_hide_out_of_stock_items( $template_name, $template_path, $located, $args ) {
    if( $template_name !== “single-product/related.php” ) {
    return;
    }

    add_filter( ‘pre_option_woocommerce_hide_out_of_stock_items’, function( $option ) { return “yes”; }, 10, 1 );
    }

    function iconic_disable_hide_out_of_stock_items( $template_name, $template_path, $located, $args ) {
    if( $template_name !== “single-product/related.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 );

    • This reply was modified 6 years, 6 months ago by Anas Mohammad.
    Linda

    (@lindamork)

    Automattic Happiness Engineer

    Hi there,

    Here’s a link to a snippet which might work for you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude Stock out products from Related products’ is closed to new replies.