Polylang – translate “Bulk table message”
The Bulk Table Message is a custom text string you set per rule inside Advanced Dynamic Pricing for WooCommerce — it appears above or within the bulk pricing table on the product page to explain the discount tier to the customer. By default, Advanced Dynamic Pricing stores this message as a plain string with no multilingual awareness, which means Polylang cannot pick it up automatically through its standard string scanning.
This article shows how to register your bulk table messages with Polylang’s string translation system and apply the correct translated version at runtime — with no additional plugins or complex setup required.
Code Sample
Add the following snippet to your child theme’s functions.php or the Code Snippets plugin. Replace BULK TEXT and BULK TEXT2 with the exact strings you entered in the Bulk Table Message field of each rule:
|
1 2 3 4 5 6 7 8 |
add_action('init', function() { pll_register_string('bulk-text-1', 'BULK TEXT', 'Advanced dynamic pricing'); pll_register_string('bulk-text-1', 'BULK TEXT2', 'Advanced dynamic pricing'); }); add_filter('wdp_format_bulk_table_message', function($s){ return pll__($s); }); |
Code Explained (for Developers)
| Element | Description |
|---|---|
add_action( 'init', ... ) | Fires after WordPress and all plugins initialise, which is the correct moment for Polylang string registration. Registering strings earlier risks Polylang’s API not being ready yet. |
pll_register_string( $name, $string, $group ) | A Polylang function that tells the plugin a specific string exists and needs a translation. $name is a unique internal identifier for each string (must differ per entry). $string is the exact text value matching what you typed in the rule’s Bulk Table Message field. $group groups all related strings together under a single label in the Polylang admin — using 'Advanced dynamic pricing' keeps all plugin strings organised in one place. |
'bulk-text-1' / 'bulk-text-2' | Unique keys for each registered string. Add one pll_register_string() call per bulk table message across all your rules, using a different key for each. |
wdp_format_bulk_table_message | An Advanced Dynamic Pricing filter that fires just before the plugin renders the bulk table message string on the front end. Returning a modified string here replaces what the customer sees. |
pll__( $s ) | A Polylang function that looks up the translation of $s for the current active language and returns it. If no translation exists for the current language, it falls back to the original string transparently. |
Key concept:
pll_register_string()only makes a string visible to Polylang — it does not perform the translation itself. The actual translation happens inpll__()at render time, which looks up whatever translation you entered in the Polylang admin for the current site language.
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 child theme’s
functions.phpor create a new dedicated snippet. - Replace
'BULK TEXT'and'BULK TEXT2'with the exact text strings you entered in the Bulk Table Message field of each pricing rule. The strings must match character-for-character, including capitalisation. - Add a separate
pll_register_string()line for each unique bulk message across all your rules, using a different key name for each (e.g.'bulk-text-3','bulk-text-4'). - Save the file or snippet.
- Go to Languages → String Translations in your WordPress admin.
- Open the group dropdown and select Advanced dynamic pricing.
- You will see all your registered bulk table message strings listed. Enter the translation for each language column and save.
- Switch your store to a non-default language and visit a product page that displays a bulk table to verify the translated message appears correctly.
⚠️ Always use a child theme or Code Snippets rather than editing the parent theme’s
functions.phpdirectly — parent theme files get overwritten on theme updates.
Adding More Bulk Table Messages
Every unique bulk table message string across all your rules needs its own pll_register_string() call. Expand the init action block as your rules grow:
|
1 2 3 4 5 6 |
add_action( 'init', function() { pll_register_string( 'bulk-text-1', 'Buy more, save more!', 'Advanced dynamic pricing' ); pll_register_string( 'bulk-text-2', 'Volume discount available', 'Advanced dynamic pricing' ); pll_register_string( 'bulk-text-3', 'Special wholesale pricing', 'Advanced dynamic pricing' ); pll_register_string( 'bulk-text-4', 'Order 10+ for extra savings', 'Advanced dynamic pricing' ); } ); |
You don’t need to restart or flush anything after adding new strings — they appear in Languages → String Translations automatically on the next page load.
When Should You Use This?
This setup suits any multilingual WooCommerce store running Polylang that uses the Bulk Table Message field in Advanced Dynamic Pricing rules. Without this snippet, every language on your site shows the same default-language message above the bulk pricing table — regardless of which language the customer browses in. With the snippet in place, each language displays its own translated version of the message automatically.