Created
September 28, 2020 15:11
-
-
Save seostudio/0b0ab0265d84fdf2bcc6ba3502d0c3f7 to your computer and use it in GitHub Desktop.
Hide out of stock products in woocommerce related products
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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