1

I am looking to make some modifications to a function in WooCommerce, on a file called class-wc-product-variation.php in woocommerce/includes/

The function I'm looking to modify is:

public function variation_is_visible() {
    $visible = true;

    // Published == enabled checkbox
    if ( get_post_status( $this->variation_id ) != 'publish' ) {
        $visible = false;
    }

    // Out of stock visibility
    elseif ( get_option('woocommerce_hide_out_of_stock_items') == 'yes' && ! $this->is_in_stock() ) {
        $visible = false;
    }

    // Price not set
    elseif ( $this->get_price() === "" ) {
        $visible = false;
    }

    return apply_filters( 'woocommerce_variation_is_visible', $visible, $this->variation_id, $this->id );
}

I need to add another elseif line in there like so:

    elseif ( get_option('woocommerce_hide_out_of_stock_items') != 'yes' && ! $this->is_in_stock() ) {
        $visible = false;
    }

How do I do this without making changes to the core files?

Rocky
  • 43
  • 4

1 Answers1

1

You should never modify the core files in plugin. In the given function, there is filter woocommerce_variation_is_visible available. Use that filter to customize as per your need. Code in core file is:

return apply_filters( 'woocommerce_variation_is_visible', $visible, $this->variation_id, $this->id );
Nilambar Sharma
  • 1,732
  • 6
  • 18
  • 23
  • How will this look like in my child theme's functions.php? I'm not too sure what to throw on there. I imagine it would be: add_filter( 'woocommerce_variation_is_visible', 'custom_variation_is_visible'); Are there other variables that should go on there? What should go in the function itself? – Rocky Oct 28 '14 at 14:44