Advertisement
fauzanjeg

JKIT || Hide Out of Stock Items

Dec 5th, 2024
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.61 KB | None | 0 0
  1. /**
  2.  * JKIt Hide Out of Stock Items
  3.  *
  4.  * Hide Out of Stock Product in Jeg Elementor Kit Query's
  5.  * Executed if is Jeg Elementor Kit Query and Post Type is Product (WooCommerce)
  6.  *
  7.  * @param array $args \WP_Query Arguments.
  8.  * @param array $attr Attribute.
  9.  */
  10. function jkit_hide_out_of_stock_items( $args, $attr ) {
  11.     if ( isset( $attr['post_type'] ) && 'product' === $attr['post_type'] ) {
  12.         $args['meta_key']     = '_stock_status';
  13.         $args['meta_value']   = 'outofstock';
  14.         $args['meta_compare'] = '!=';
  15.     }
  16.  
  17.     return $args;
  18. }
  19. add_filter( 'jeg_default_query_args', 'jkit_hide_out_of_stock_items', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement