skip to Main Content

I have a WooCommerce store and am using the ‘Advanced Dynamic Pricing for Woocommerce’ plugin. I need to use this plugin because I have discount structures set up

Percentage discounts have been applied to all products in store. The original price is crossed out with the new price next to it.

enter image description here

I want to display a suffix next to the new price that says ‘inc VAT’ to indicate that the price is inclusive of VAT.

I have tried this code which seems to work on products that don’t have discounts applied but not on discounted products.

add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
function custom_price_suffix( $price, $product ){
$price = $price . 'inc VAT' ;
return apply_filters( 'woocommerce_get_price', $price );}

Anyone know how I can achieve this?

The generated HTML code looks like this:

<div class="woosg-price">
<div class="woosg-price-ori">
<del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">£</span>262.00</span>
</del> 
<ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price- 
currencySymbol">£</span>117.90</span></ins> 
</div>
<div class="woosg-price-new"></div>
</div>

2

Answers


  1. You Can add Suffix using the below filter.

    add_filter( 'woocommerce_get_price_suffix', 'swt_add_price_suffix', 99, 4 );
      
    function swt_add_price_suffix( $html, $product, $price, $qty ){
        $html .= ' inc VAT';
        return $html;
    }
    

    Or You can use below code as well.

    add_filter( 'woocommerce_get_price_html', 'swt_add_price_suffix', 99, 2 );
      
    function swt_add_price_suffix( $price, $product ){
        $price = $price.' inc VAT';
        return $price;
    }
    

    You can add suffix from the WooCommerce settings using the below steps.

    1. Goto WooCommerce -> Settings -> General.
    2. Mark checked "Enable tax rates and calculations" checkbox.
    3. Open the Tax Tab.
    4. Add the suffix text in "Price display suffix" text field.
    5. Save the settings.
    Login or Signup to reply.
  2. You can use woocommerce_get_price_suffix dedicated hook, targeting on sale products like:

    add_filter( 'woocommerce_get_price_suffix', 'custom_price_suffix', 999, 4 );
    function custom_price_suffix( $html, $product, $price, $qty ){
        if ( $product->is_on_sale() ) {
            return  ' ' .  __('inc VAT', 'woocommerce');
        }
        return $html;
    }
    

    or maybe this instead (because of Advanced Dynamic Pricing for Woocommerce plugin):

    add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 999, 2 );
    function custom_price_suffix( $price_html, $product ){
        if ( $product->is_on_sale() ) {
            $price_html .= ' ' .  __('inc VAT', 'woocommerce');
        }
        return $price_html;
    }
    

    Code goes in functions.php file of the active child theme (or active theme). Tested and works.

    Related:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search