Advertisement
businessdad

WooCommerce - Append price with/without tax to product price

Aug 27th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. /**
  2.  * Appends a second product price, with or without tax, to the displayed prices.
  3.  *
  4.  * @param string price_html The original product price.
  5.  * @param WC_Product product A product.
  6.  * @return string
  7.  * @author Aelia <support@aelia.co>
  8.  */
  9. add_filter('woocommerce_get_price_html', function($price_html, $product) {
  10.   $price_incl_tax = $product->get_price_including_tax();
  11.   $price_excl_tax = $product->get_price_excluding_tax();
  12.  
  13.   // No need to display two prices if the one with and without tax are the same
  14.   if($price_incl_tax != $price_excl_tax) {
  15.     $price_html .= '<span class="extra_price">';
  16.     // Only enable the require line
  17.     // The following line displays the price WITH tax
  18.     //$price_html .= wc_price($product->get_price_including_tax());
  19.     // The following line displays the price WITHOUT tax
  20.     $price_html .= wc_price($product->get_price_excluding_tax());
  21.  
  22.     $price_html .= '</span>';
  23.   }
  24.   return $price_html;
  25. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement