1

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 2

1

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:

4
  • Thanks for the suggestions, however these have not worked. I can enable the price suffix via the WooCommerce settings which will display when showing the retail price. However when I log in as a customer with a discount, it displays the retail price crossed out with the new price, which is what I want, but the suffix wont display.
    – Chris
    Commented Oct 21, 2020 at 9:26
  • @Chris The code works on default woocommerce without your plugin. Try to increase the hook priority to 999999 instead of 999, to see if it change something… Commented Oct 21, 2020 at 9:41
  • Thanks, just tried that but it changed nothing, i think it must be a conflict with the plugin. The issue is i need to use the plugin because it manages my discount structures perfectly
    – Chris
    Commented Oct 21, 2020 at 9:56
  • 1
    Just to update, the above code worked when I updated the advanced dynamic pricing plugin. Thank you!
    – Chris
    Commented Oct 21, 2020 at 10:30
0

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.
1
  • Thanks for the suggestions, however these have not worked. I can enable the price suffix via the WooCommerce settings which will display when showing the retail price. However when I log in as a customer with a discount, it displays the retail price crossed out with the new price, which is what I want, but the suffix wont display.
    – Chris
    Commented Oct 21, 2020 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.