Advanced Dynamic Pricing For WooCommerce

WooCommerce Advanced Product Labels, by Jeroen Sormani

WooCommerce Advanced Product Labels by Jeroen Sormani lets you display custom promotional labels on product images — showing text, percentages, or price differences using dynamic placeholders like {percentage}, {discount}, {price}, {saleprice}, and {delprice}. Its built-in smart label filter (wapl_smart_product_label_filter) calculates those placeholder values by reading WooCommerce’s native sale price fields. When Advanced Dynamic Pricing for WooCommerce applies a discount dynamically at runtime, it doesn’t write the discounted price back to the native sale price field — so the Advanced Product Labels plugin reads the wrong value and populates its placeholders incorrectly.

This article provides a replacement filter that calculates label placeholder values from the actual current prices, supporting simple, variable, and composite product types.


Required Settings Before Adding the Code

Before applying the snippet, confirm these two Advanced Dynamic Pricing settings are correct.

Go to Advanced Dynamic Pricing → Settings → Calculation and turn “Use prices modified by other plugins” to ON. Then go to Advanced Dynamic Pricing → Settings → System and turn “Suppress other pricing plugins in frontend” to OFF. Save both pages before continuing.


Code Sample

Add the following snippet to your child theme’s functions.php or the Code Snippets plugin:

 Code Explained (for Developers)

The snippet replaces the Advanced Product Labels plugin’s default wapl_smart_product_label_filter with a custom implementation that handles all three product types and resolves the placeholder values from the live price getters rather than the stored sale price fields.

Hook swap

ElementDescription
remove_filter( 'wapl_product_label', 'wapl_smart_product_label_filter' )Detaches the default smart label filter that ships with Advanced Product Labels. This filter reads get_sale_price() directly, which returns the stored database value rather than the price Advanced Dynamic Pricing calculates at runtime.
add_filter( 'wapl_product_label', function( $label ) { ... } )Registers the replacement filter on the same hook. It receives $label — the raw label template string containing placeholders like {percentage} — and returns the final string with all placeholders replaced.

Global product resolution

ElementDescription
global $productAccesses the WooCommerce global product variable set by the current loop or product page context.
Admin preview fallbackIf $product is empty (e.g. when previewing a label in the Advanced Product Labels admin), the snippet fetches one product via get_posts() so the preview renders rather than throwing an error.
wc_get_product( $product )Normalises $product to a proper WC_Product object regardless of whether the global held a post object, a product ID, or an existing product object.
trigger_error(...)Fires a PHP notice if normalisation fails, helping developers identify context problems during development without causing a fatal error.

Product type branches

BranchProduct typesPrice getters used
Compositecompositeget_composite_regular_price() and get_composite_price() — composite-specific methods from the WooCommerce Composite Products plugin.
Simple / externalAll non-variable, non-compositeget_regular_price() and get_sale_price() — standard WooCommerce getters that return the current (dynamically modified) prices.
VariablevariableLoops all child variations via get_children(), finds the one with the highest discount percentage, then uses get_variation_regular_price('min') and get_variation_sale_price('min') for the final placeholder values.

Placeholder replacement

PlaceholderReplacement value
{percentage}The highest discount percentage across all applicable product types, rounded via the wapl_filter_discount_round filter (default: 1 decimal place).
{discount}The absolute price difference between regular and sale price, formatted as a currency string via wc_price().
{price}The regular price formatted as currency.
{saleprice}The current sale/discounted price formatted as currency.
{delprice}The regular price wrapped in a <del> HTML tag for strikethrough display.

Key concept: Using get_sale_price() and get_regular_price() in the 'view' context (the default) returns the prices as Advanced Dynamic Pricing has modified them at runtime — not the raw database values. This makes the placeholder calculations correct for dynamically discounted products without requiring any extra calls to the plugin’s internal API.


How to Apply This Code

  1. Go to Advanced Dynamic Pricing → Settings → Calculation and enable “Use prices modified by other plugins”. Save the page.
  2. Go to Advanced Dynamic Pricing → Settings → System and disable “Suppress other pricing plugins in frontend”. Save the page.
  3. Open Appearance → Theme File Editor in your WordPress admin, or open the Code Snippets plugin.
  4. Paste the full snippet into your child theme’s functions.php or create a new dedicated snippet.
  5. Save the file or snippet.
  6. Visit a product page or shop page where Advanced Product Labels displays a label with percentage or price placeholders.
  7. Verify that the {percentage}, {discount}, {saleprice}, and other placeholders now reflect the dynamically discounted price rather than the original stored sale price.
  8. Also check the Advanced Product Labels admin preview to confirm it renders without errors.

⚠️ Always use a child theme or Code Snippets rather than editing the parent theme’s functions.php directly — parent theme files get overwritten on theme updates.


When Should You Use This?

This fix applies when you notice product labels from Advanced Product Labels showing the wrong discount percentage, an incorrect sale price, or a {percentage} placeholder that doesn’t match the discount Advanced Dynamic Pricing actually applies. It also covers situations where labels display 0% or show the original product sale price instead of the dynamically calculated one. If you use composite products alongside either plugin, this snippet handles that case too.

Have questions? Please submit a support request. We're always happy to help!

Advanced Dynamic Pricing
for WooCommerce
PRO

From $60
Buy
✓ 30-day money-back guarantee