Hi,
I'm a complete novice to PHP but have been using Wordpress for many years which has included adding various PHP codes for templates which I usually source from either the wordpress.org website or from forums. A few months back I set up some code on my site which I'll explain more below; it worked fine but since updates it no longer functions as it should and I'm pretty sure it's a basic fix needed but as I've not been able to get my head around the code I'm at a bit of a loss on how to fix it; which has led me to here.
If someone could help me with the below, and if you specialise in PHP please also leave me your contact details as I have on going work on Wordpress and would gladly pass anything I can your way.
The problem:
I'm using the latest version of Wordpress with the plugin WooCommerce for the shop. The code I added is to the single-product.php template. All the code done was display the price, the VAT and the price + VAT, so basically 3 lines showing a breakdown of the price. Rather than just the total which displays by default. I think WooCommerce had an update which means I need to adjust my code but I have no idea what to change. The code is no longer live on my website but if you need to see a live example to understand what's going on please let me know and I'll set it up again so you can see it, please find the code below I look forward to your replies 😃
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">+ VAT = <?php echo wc_price( $tax_amount ); ?></span><br>
<span class="price price-incl">Total = <?php echo wc_price( $price_incl_tax ); ?></span>