wc_get_price_to_display
This commit is contained in:
parent
38ab3d63f6
commit
67c01ff101
|
@ -119,6 +119,19 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
|
|||
return wc_get_price_including_tax( $this, array( 'qty' => $qty, 'price' => $price ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
|
||||
*
|
||||
* @deprecated 2.7.0 Use wc_get_price_to_display instead.
|
||||
* @param string $price to calculate, left blank to just use get_price()
|
||||
* @param integer $qty passed on to get_price_including_tax() or get_price_excluding_tax()
|
||||
* @return string
|
||||
*/
|
||||
public function get_display_price( $price = '', $qty = 1 ) {
|
||||
_deprecated_function( 'WC_Product::get_display_price', '2.7', 'wc_get_price_to_display' );
|
||||
return wc_get_price_to_display( $this, array( 'qty' => $qty, 'price' => $price ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price (excluding tax) - ignores tax_class filters since the price may *include* tax and thus needs subtracting.
|
||||
* Uses store base tax rates. Can work for a specific $qty for more accurate taxes.
|
||||
|
|
|
@ -1669,24 +1669,6 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
return apply_filters( 'woocommerce_get_price', $price, $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
|
||||
*
|
||||
* @param string $price to calculate, left blank to just use get_price()
|
||||
* @param integer $qty passed on to get_price_including_tax() or get_price_excluding_tax()
|
||||
* @return string
|
||||
*/
|
||||
public function get_display_price( $price = '', $qty = 1 ) {
|
||||
if ( '' === $price ) {
|
||||
$price = $this->get_price();
|
||||
}
|
||||
|
||||
$tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
|
||||
$display_price = ( 'incl' === $tax_display_mode ) ? $this->get_price_including_tax( $qty, $price ) : $this->get_price_excluding_tax( $qty, $price );
|
||||
|
||||
return apply_filters( 'woocommerce_get_display_price', $display_price, $price, $qty );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price in html format.
|
||||
*
|
||||
|
|
|
@ -977,3 +977,22 @@ function wc_get_price_excluding_tax( $product, $args ) {
|
|||
|
||||
return apply_filters( 'woocommerce_get_price_excluding_tax', $price, $qty, $product );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the price including or excluding tax, based on the 'woocommerce_tax_display_shop' setting.
|
||||
* @since 2.7.0
|
||||
* @param WC_Product $product
|
||||
* @param array $args
|
||||
* @return float
|
||||
*/
|
||||
public function wc_get_price_to_display( $product, $args ) {
|
||||
$args = wp_parse_args( $args, array(
|
||||
'qty' => 1,
|
||||
'price' => $product->get_price(),
|
||||
) );
|
||||
|
||||
$price = $args['price'];
|
||||
$qty = $args['qty'];
|
||||
|
||||
return 'incl' === get_option( 'woocommerce_tax_display_shop' ) ) ? wc_get_price_including_tax( $product, array( 'qty' => $qty, 'price' => $price ) ) : wc_get_price_excluding_tax( $product, array( 'qty' => $qty, 'price' => $price );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue