Advanced Dynamic Pricing For WooCommerce

Show discount message on the product page by the shortcode

Advanced Dynamic Pricing for WooCommerce PRO includes an Advertising feature that lets you configure promotional discount messages — shown to customers to encourage them to take advantage of active pricing rules. By default, these messages appear in a fixed position determined by the plugin’s settings.

This article explains how to register a custom shortcode that lets you place the advertising discount message at any location on the product page — inside a page builder, a widget area, a custom template, or any theme position that supports shortcodes.

⚠️ This feature requires the PRO version of Advanced Dynamic Pricing for WooCommerce. The Advertising module and ADPFactory class used in this snippet are not available in the free version.


Code Sample

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

Once the snippet is saved, place the following shortcode at any location on your product page where you want the discount message to appear:


Code Explained (for Developers)

ElementDescription
add_shortcode( 'adp_advertising_message_product_page', ... )Registers a new WordPress shortcode with the tag adp_advertising_message_product_page. Once registered, this shortcode can be placed anywhere WordPress processes shortcodes: page builders, theme templates, widget areas, or directly in post content.
ADPFactory::get( '...' )The plugin’s internal service locator / factory class. It resolves and returns a fully initialised instance of the requested service class, handling all dependency injection internally. This is the correct way to retrieve plugin service objects — do not instantiate them directly with new.
'Advertising_AdvertisingMessage_AdvertisingMessageDisplay'The service identifier string for the PRO-only advertising message display class. This maps to ADPProVersionIncludesAdvertisingAdvertisingMessageAdvertisingMessageDisplay as noted in the PHPDoc comment above it.
/** @var ... $advertisingMessageDisplay */A PHPDoc type hint for IDE autocompletion. It tells your code editor the exact fully-qualified class name of the resolved object so you get method suggestions. It has no effect at runtime.
ob_start()Starts output buffering. The showMessageAtProductPage() method echoes HTML directly, so buffering is required to capture that output as a string rather than sending it straight to the browser.
$advertisingMessageDisplay->showMessageAtProductPage()Calls the plugin’s internal method that renders the advertising discount message configured for the current product page. It reads the active rules and the configured advertising message settings from Advanced Dynamic Pricing → Settings → Advertising.
return ob_get_clean()Ends output buffering, retrieves the captured HTML, and returns it as the shortcode’s output. This is the standard WordPress pattern for shortcodes that need to return HTML produced by echoing functions.

Key concept: WordPress shortcodes must return HTML rather than echo it directly. Since showMessageAtProductPage() echoes its output, the output buffer captures it and ob_get_clean() converts it into a returnable string — making it fully compatible with the shortcode system.


How to Place the Shortcode

Once the snippet is saved, you can place [adp_advertising_message_product_page] in any of the following locations:

In a page builder (Elementor, Divi, WPBakery, etc.) Add a Shortcode block or Text/HTML element and paste [adp_advertising_message_product_page] into it.

In a WooCommerce product page hook via PHP

WooCommerce single product hook position reference:

HookDefault priorityPosition
woocommerce_single_product_summary at 5After product title
woocommerce_single_product_summary at 10After product rating
woocommerce_single_product_summary at 20After product price
woocommerce_single_product_summary at 25(custom — good placement for a discount message)
woocommerce_single_product_summary at 30After excerpt/description
woocommerce_single_product_summary at 40After Add to Cart button

Directly in a WooCommerce template (advanced) If you have replaced the product page template in your child theme, you can call the shortcode directly in the template file:


Configuring the Advertising Message

The content and appearance of the message displayed by this shortcode is controlled in the plugin’s Advertising settings. To configure it:

  1. Go to Advanced Dynamic Pricing → Settings → Advertising.
  2. Set up your promotional message text, conditions, and display rules.
  3. Make sure the advertising message is set to display on the product page.
  4. Save settings and visit a product page to confirm the message appears at your chosen shortcode location.

⚠️ If the shortcode outputs nothing, the most likely cause is that no advertising message is configured or enabled in Settings → Advertising, or the current product does not match any active advertising rule conditions.


How to Apply This Code

  1. Open Appearance → Theme File Editor in your WordPress admin, or open the Code Snippets plugin.
  2. Paste the snippet into your active child theme’s functions.php or create a dedicated snippet.
  3. Save the snippet.
  4. Navigate to any product page and place [adp_advertising_message_product_page] at the location where the message should appear — either via a page builder, a hook, or directly in a template.
  5. Verify that the discount message is rendering correctly for products with active advertising rules.

⚠️ Editing functions.php directly 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?

  • The default advertising message position set by the plugin does not match your theme layout and you need it at a specific custom position on the product page.
  • You are using a page builder (Elementor, Divi, etc.) to build product page templates and need to inject the message using a shortcode block.
  • You want the discount message to appear conditionally in a specific widget area or content zone that only supports shortcodes.
  • You are building a custom product page template in your child theme and want full control over message placement.
  • You want to place the same advertising message in multiple locations on the same product page.

Add the code below into the functions.php file of your theme or as a new snippet, using your code snippets plugin, and put the shortcode [adp_advertising_message_product_page] at the necessary place on the product page

 

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