WooCommerce_Hide_Password_Protected_Products

The WooCommerce Hide Password Protected Products WooCommerce Hide Password Protected Products class.

Defined (1)

The class is defined in the following location(s).

/woocommerce-hide-password-protected-products.php  
  1. class WooCommerce_Hide_Password_Protected_Products { 
  2.  
  3. /** 
  4. * The Constructor 
  5. */ 
  6. public function __construct() { 
  7. add_action( 'pre_get_posts', array( $this, 'alter_product_query' ), 11 ); 
  8.  
  9. /** 
  10. * Alter the WooCommerce product query 
  11. * @param $q 
  12. * @since 1.0.0 
  13. * @access public 
  14. */ 
  15. public function alter_product_query( $q ) { 
  16.  
  17. if ( ! is_admin() && ! is_single() && isset( $q->query ) && isset( $q->query['post_type'] ) && 'product' == $q->query['post_type'] ) { 
  18. add_filter( 'posts_where', array( $this, 'exclude_protected_products' ) ); 
  19.  
  20. /** 
  21. * Prevent password protected products appearing in the loops 
  22. * @param string $where 
  23. * @return string 
  24. */ 
  25. public function exclude_protected_products( $where ) { 
  26. global $wpdb; 
  27. $where .= " AND {$wpdb->posts}.post_password = ''"; 
  28.  
  29. return $where;