Displaying the price of a Woocommerce product with and without tax and tax amount

I use WooCommerce for WordPress and list products without tax.

I need to separately show the price (without tax), tax and price + tax on the product page (as on the checkout page).

I could not find a plugin that does this.

How can i do this?

+7
source share
5 answers

WooCommerce v3.0.0
3.0 WooCommerce, woocommerce_price() , get_price_include_tax(). wc_get_price_include_tax:

<?php echo wc_price( wc_get_price_including_tax( $product ) ); ?>

WooCommerce v3.0.0
. WooCommerce, , WooCommerce. WooCommerce .

price.php , , ():

<?php echo woocommerce_price( $product->get_price_including_tax() ); ?>

. price.php price.php wp-content/themes/[your theme folder]/woocommerce/single-product/price.php

+14

2018/2019 ( Woocommerce 3+)

+ + , ( ):

" Woocommerce "

1) single-product/price.php single-product/price.php ( ).

:

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

global $product;

// 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
?>
<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 without VAT
    $price_incl = $product->get_price_including_tax();  // price included VAT
    $tax_amount = $price_incl - $price_excl; // VAT price amount
?>
    <p class="price"><?php echo woocommerce_price( $price_excl ); /* without VAT */ ?></p> (formatted)
    <p class="price-vat"><?php echo woocommerce_price( $tax_amount); /* VAT */ ?></p>
    <p class="price-and-vat"><?php echo woocommerce_price( $price_incl); /* With VAT  */ ?></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( ) // Get the suffix to display after prices > 0.
$currency = esc_attr( get_woocommerce_currency( ) ) // Get the currency code.
get_woocommerce_currency_symbol( $currency ) // Get the currency symbol.
get_tax_class( ) // Returns the tax class.
get_tax_status( ) // Returns the tax status.

: WooCommerce WC_Product

+8

. Woocommerce:

  • Woocommerce: "": / .
+6

, 3.5.4 2019 . , Woo Commerce .

0

, , , ,

0

All Articles