1
votes

prices in my shop are displayed with tax and also I'm using {price_excluding_tax} suffix to display also price excluding tax. But there is a problem with variable products... The shop shows only prices including tax (and the old price in case of promotion) but it doesn't shows the price excluding tax. Prices for both variable products are the same. I tried to use this code:

https://tomjesch.com/display-woocommerce-products-with-and-without-tax/

But it doesn't work properly - it shows prices, but does not react to any price change in the woocommerce admin panel. So, it works fine only when adding a new product.

Thanks in advance...

My code:

function edit_price_display() {
  $product         = WC_Product( get_the_ID() );
  $regular_price   = $product ->regular_price;
  $price           = $product->price;

  $price_incl_tax  = $price + round( $price * ( 23 / 100 ), 2 ); 
  $price_incl_tax  = number_format( $price_incl_tax, 2, ",", "" ); 
  $price           = number_format( $price, 2, ",", "" ); 

  $display_price   = '<ins><span class="woocommerce-Price-amount amount">';
  $display_price  .= ' '.$price_incl_tax .'<span class="woocommerce-Price-currencySymbol">&nbsp;zł</span>';
  $display_price  .= '</span></ins>&nbsp;';
  $display_price  .= '<small class="woocommerce-price-suffix">(netto: <span class="woocommerce-Price-amount amount">'.$price .'&nbsp;<span class="woocommerce-Price-currencySymbol">zł</span></span>)</small>';

  $display_price .= '';

  $display_regular_price ='<del><span class="woocommerce-Price-amount amount">'.$regular_price .'<span class="woocommerce-Price-currencySymbol">&nbsp;zł</span></span></del>';


  if($product->is_on_sale()) {
    echo $display_regular_price;    
  }
  echo $display_price;
}
add_filter('woocommerce_variable_price_html', 'edit_price_display');
1
Can you share your code?Clinton J
Hi, I've pasted the code above.Badger

1 Answers

3
votes

Bear in mind Woocommerce developers comment about that feature: https://github.com/woocommerce/woocommerce/issues/14839

But if you need achive such reasult, you can do that in this way:

add_filter( 'woocommerce_get_price_html', 'my_price_prefix_suffix', 100, 2 );

function my_price_prefix_suffix( $price, $product ){
    // To add suffix, go to /wp-admin/admin.php?page=wc-settings&tab=tax
    if($product->is_type( 'variable' ) && $product->is_in_stock()){
        $price =  $price . '('.wc_price($product->get_variation_regular_price()* 1.23).' z Vat)';
    }
    return apply_filters( 'woocommerce_get_price', $price );
}

Code is tested an working as expected.