2018/2019 ( Woocommerce 3+)
+ + , ( ):
" Woocommerce "
1) single-product/price.php single-product/price.php ( ).
:
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $product;
$price_excl_tax = wc_get_price_excluding_tax( $product );
$price_incl_tax = wc_get_price_including_tax( $product );
$tax_amount = $price_incl_tax - $price_excl_tax;
?>
<p class="price-excl"><?php echo wc_price( $price_excl_tax ); ?></p>
<p class="tax-price"><?php echo wc_price( $tax_amount ); ?></p>
<p class="price-incl"><?php echo wc_price( $price_incl_tax ); ?></p>
2) loop/price.php loop/price.php ( ).
:
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
global $product;
if ( $product->get_price_html() ) :
// Get the prices
$price_excl_tax = wc_get_price_excluding_tax( $product ); // price without VAT
$price_incl_tax = wc_get_price_including_tax( $product ); // price with VAT
$tax_amount = $price_incl_tax - $price_excl_tax; // VAT amount
// Display the prices
?>
<span class="price price-excl"><?php echo wc_price( $price_excl_tax ); ?></span><br>
<span class="price tax-price"><?php echo wc_price( $tax_amount ); ?></span><br>
<span class="price price-incl"><?php echo wc_price( $price_incl_tax ); ?></span>
<?php endif ?>
:
• Woocommerce
• wc_get_price_including_tax()
• wc_get_price_excluding_tax()
• wc_price()
• wc_get_price_to_display()
( woocommerce 3):
, , WooCommerce Tax .
cale_b, woocommerce templates . woocommerce. woocommerce woocommerce single-product price.php , .
single-product/price.php single-product/price.php global $product; :
?>
<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<?php
$price_excl = $product->get_price_excluding_tax();
$price_incl = $product->get_price_including_tax();
$tax_amount = $price_incl - $price_excl;
?>
<p class="price"><?php echo woocommerce_price( $price_excl ); ?></p> (formatted)
<p class="price-vat"><?php echo woocommerce_price( $tax_amount); ?></p>
<p class="price-and-vat"><?php echo woocommerce_price( $price_incl); ?></p>
<meta itemprop="price" content="<?php echo esc_attr( $product->get_price() ); ?>" />
<meta itemprop="priceCurrency" content="<?php echo esc_attr( get_woocommerce_currency() ); ?>" />
<link itemprop="availability" href="http://schema.org/<?php echo $product->is_in_stock() ? 'InStock' : 'OutOfStock'; ?>" />
</div>
, , php woocommerce, :
get_price_suffix( )
$currency = esc_attr( get_woocommerce_currency( ) )
get_woocommerce_currency_symbol( $currency )
get_tax_class( )
get_tax_status( )
: WooCommerce WC_Product