wc_get_min_max_price_meta_query

Get min/max price meta query args.

Description

(array) wc_get_min_max_price_meta_query( (array) $args ); 

Returns (array)

Parameters (1)

0. $args (array)
Min price and max price arguments.

Usage

  1. if ( !function_exists( 'wc_get_min_max_price_meta_query' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; 
  3.  
  4. // Min price and max price arguments. 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_get_min_max_price_meta_query($args); 
  9.  

Defined (1)

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

/includes/wc-product-functions.php  
  1. function wc_get_min_max_price_meta_query( $args ) { 
  2. $min = isset( $args['min_price'] ) ? floatval( $args['min_price'] ) : 0; 
  3. $max = isset( $args['max_price'] ) ? floatval( $args['max_price'] ) : 9999999999; 
  4.  
  5. /** 
  6. * Adjust if the store taxes are not displayed how they are stored. 
  7. * Max is left alone because the filter was already increased. 
  8. * Kicks in when prices excluding tax are displayed including tax. 
  9. */ 
  10. if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) { 
  11. $tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() ); 
  12. $class_min = $min; 
  13.  
  14. foreach ( $tax_classes as $tax_class ) { 
  15. if ( $tax_rates = WC_Tax::get_rates( $tax_class ) ) { 
  16. $class_min = $min - WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $min, $tax_rates ) ); 
  17.  
  18. $min = $class_min; 
  19.  
  20. return array( 
  21. 'key' => '_price',  
  22. 'value' => array( $min, $max ),  
  23. 'compare' => 'BETWEEN',  
  24. 'type' => 'NUMERIC',  
  25. );