The original price for variations must be shown before the discount
When Advanced Dynamic Pricing for WooCommerce applies a discount rule to a variable product, it modifies the displayed price HTML to show the discounted price range. In some cases this can suppress the original pre-discount price display on the product page — meaning shoppers only see the new price without being shown what it was reduced from.
This article provides a compact snippet that disables Advanced Dynamic Pricing’s price HTML modification specifically for variable products on the product page, restoring WooCommerce’s default behaviour of showing the original price alongside the discounted one so the price reduction is clearly communicated to shoppers.
Code Sample
Add the following snippet to your theme’s functions.php or the Code Snippets plugin:
|
1 2 3 4 5 6 |
add_filter( "adp_get_price_html_is_mod_needed", function ( $mod, $product, $context ) { if ( $product->is_type( 'variable' ) && $context->is( $context::WC_PRODUCT_PAGE ) ) { return false; } return $mod; }, 10, 3 ); |
Code Explained (for Developers)
| Element | Description |
|---|---|
adp_get_price_html_is_mod_needed | A custom filter hook provided by Advanced Dynamic Pricing. It fires during the plugin’s price HTML rendering step and determines whether the plugin should modify the price HTML output for the current product in the current display context. Returning true allows the modification; returning false tells the plugin to leave the price HTML as WooCommerce would render it natively. |
$mod | A boolean value — the current state of the modification flag. true means the plugin intends to modify the price HTML; false means it should not. This is the value you either pass through or override. |
$product | The WC_Product object for the product currently being rendered. Used here to check whether the product is of type variable. |
$context | A context object provided by the plugin that describes where the price is being displayed. Exposes constants and an is() method for checking the current rendering location. |
$product->is_type( 'variable' ) | Returns true only for variable products — simple, external, and variation products are unaffected by this snippet, so their price HTML continues to be modified by the plugin as normal. |
$context->is( $context::WC_PRODUCT_PAGE ) | Checks whether the price is being rendered on the single product page specifically. This prevents the snippet from affecting price display in other contexts such as the shop/category loop, cart, or checkout — the original price suppression fix only applies where the shopper is evaluating the product in detail. |
return false | When both conditions are met (variable product + product page context), the snippet returns false to disable the plugin’s price HTML modification, allowing WooCommerce to render the full original-plus-discounted price HTML natively. |
return $mod | For all other cases, the original $mod value is returned unchanged — ensuring the plugin behaves normally everywhere else. |
10, 3 | Hook priority 10 (standard); 3 means the callback accepts three arguments — $mod, $product, and $context. |
Key concept: The
adp_get_price_html_is_mod_neededfilter is scoped by both product type and display context. This makes it precise — you can target exactly the combination of product type and page location where the behaviour needs to change, without creating unintended side effects elsewhere on the site.
Available Context Constants
The $context object exposes constants you can use to target other display locations if needed:
| Constant | Description |
|---|---|
$context::WC_PRODUCT_PAGE | Single product page |
$context::WC_SHOP_PAGE | Main WooCommerce shop page / product archive |
$context::WC_CART | Cart page |
$context::WC_CHECKOUT | Checkout page |
For example, to also disable the price modification for variable products on the shop page, extend the condition:
|
1 2 3 4 5 6 7 8 |
add_filter( 'adp_get_price_html_is_mod_needed', function( $mod, $product, $context ) { if ( $product->is_type( 'variable' ) && ( $context->is( $context::WC_PRODUCT_PAGE ) || $context->is( $context::WC_SHOP_PAGE ) ) ) { return false; } return $mod; }, 10, 3 ); |
Targeting Other Product Types
The snippet targets only variable products. If you need to apply the same behaviour to other product types, adjust the is_type() check:
| Product type | is_type() value |
|---|---|
| Simple product | 'simple' |
| Variable product | 'variable' |
| External / affiliate product | 'external' |
| Grouped product | 'grouped' |
| Specific variation | 'variation' |
| All product types | Remove the is_type() check entirely |
To disable the modification for all product types on the product page:
|
1 2 3 4 5 6 |
add_filter( 'adp_get_price_html_is_mod_needed', function( $mod, $product, $context ) { if ( $context->is( $context::WC_PRODUCT_PAGE ) ) { return false; } return $mod; }, 10, 3 ); |
How to Apply This Code
- Open Appearance → Theme File Editor in your WordPress admin, or open the Code Snippets plugin.
- Paste the snippet into your active child theme’s
functions.phpor create a dedicated snippet. - Save and navigate to a variable product page that has an active discount rule applied.
- Verify that the original price is now displayed alongside the discounted price (typically shown as a strikethrough original price followed by the new discounted price).
⚠️ Editing
functions.phpdirectly can be overwritten during theme updates. A child theme or the Code Snippets plugin is the safer long-term approach.
When Should You Use This?
- Variable product pages show only the discounted price with no reference to the original price, making the discount invisible to shoppers.
- You want the classic WooCommerce strikethrough price display (
~~$20.00~~ $15.00) to appear for variable products with active pricing rules. - Your theme relies on WooCommerce’s native price HTML structure and Advanced Dynamic Pricing’s modification is breaking the layout or styling of the variable product price on the product page.
- You want full transparency about the discount amount on the product page while still applying the discount correctly in the cart and at checkout.
- You need the price modification to remain active on the shop/category page or in the cart but not on the individual product page.