Skip to content

Instantly share code, notes, and snippets.

@seostudio
Created September 28, 2020 15:11
Show Gist options
  • Save seostudio/0b0ab0265d84fdf2bcc6ba3502d0c3f7 to your computer and use it in GitHub Desktop.
Save seostudio/0b0ab0265d84fdf2bcc6ba3502d0c3f7 to your computer and use it in GitHub Desktop.
Hide out of stock products in woocommerce related products
<?php
class WPDeskHideOutOfStockInRelated {
public function hooks() {
add_action( 'woocommerce_after_single_product_summary', array( $this, 'add_filter' ), 19 );
add_action( 'woocommerce_after_single_product_summary', array( $this, 'remove_filter' ), 21 );
}
public function add_filter() {
add_filter( 'option_woocommerce_hide_out_of_stock_items', array( $this, 'return_yes' ) );
}
public function remove_filter() {
remove_filter( 'option_woocommerce_hide_out_of_stock_items', array( $this, 'return_yes' ) );
}
public function return_yes() {
return 'yes';
}
}
(new WPDeskHideOutOfStockInRelated())->hooks();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment