Reputation: 727
I have a setup. For products, I display prices with VAT (info added in the suffix). However, I must include a net price under this price (only in single-product-view). In addition, I have products that are without a price and with them using the Call For Price plugin to display a button to send a price inquiry.
I display the net price adding:
<?php echo woocommerce_price ($ product-> get_price_excluding_tax ()); ?>
added in the template /woocommerce/single-product/price.php
.
The problem is that in the case of a product without a price, I still see this value without tax (net) with the amount of 0.00. This one with VAT is deleted automatically.
I try also:
<?php if(woocommerce_price ($product-> get_price_excluding_tax ()) != '0.00') // If price is not equal to 0.00
{ echo woocommerce_price ($product-> get_price_excluding_tax ()); }
?>
and
<?php if( !empty(woocommerce_price ($product-> get_price_excluding_tax ()))) { echo woocommerce_price ($product-> get_price_excluding_tax ()); } ?>
Still 0,00 is visible.
How could I remove this net price in products that do not have the price indicated? Any ideas?
Upvotes: 3
Views: 1575
Reputation: 253901
Since Woocommerce version 3, woocommerce_price()
function is outdated and deprecated. It has been replaced by wc_price()
formatting function.
Same thing for get_price_excluding_tax()
method. It has been replaced by this function (where $product
is an instance of the WC_Product
object):
wc_get_price_excluding_tax( $product );
So the correct code should be:
<?php
$price_excl_tax = wc_get_price_excluding_tax( $product );
echo $price_excl_tax > 0 || ! empty( $price_excl_tax ) ? wc_price( $price_excl_tax ) . __(' netto') : '';
?>
Tested and works
Before Woocommerce version 3, you will use:
<?php
$price_excl_tax = $product->get_price_excluding_tax();
echo $price_excl_tax > 0 || ! empty( $price_excl_tax ) ? woocommerce_price( $price_excl_tax ) . __(' netto') : '';
?>
Upvotes: 1
Reputation: 75
try
<?php if (!empty(floatval(woocommerce_price($product>get_price_excluding_tax()))))
{ echo woocommerce_price($product->get_price_excluding_tax(); } ?>
Upvotes: 0