DynamicPress registers three PHP helper functions that are whitelisted for use inside Bricks Builder Code elements via the bricks/code/echo_function_names filter. This means you can call them directly from a Bricks Code element without needing a custom plugin or child theme PHP.
get_sales_percentage() #
Calculates and outputs the sale discount percentage for the current product. Handles both simple products and variable products (reads the default variation’s prices.)
| // Usage inside a Bricks Code element on a product template: get_sales_percentage(); // Output example:// <span class=”product-listing-sale-percentage”>-25.00%</span> |
| Behaviour | Detail |
| Product type | Simple and Variable products – variable reads default variation attributes |
| Output | HTML span with class product-listing-sale-percentage containing the formatted percentage |
| No sale price | Function outputs nothing (no element rendered) |
product_average_rating( $product = null ) #
Returns the WooCommerce product’s average star rating formatted to one decimal place.
| // On a product template — uses global $product automatically: echo product_average_rating(); // e.g. outputs: 4.2 // Pass a product ID directly: echo product_average_rating(42); // e.g. outputs: 3.8 // Returns null if the product is not found or has no ratings. |
bricks_get_first_char( $string = ” ) #
Returns the first character of any string. Multibyte-safe (uses mb_substr). Useful for avatar initials, alphabetical labels, or any element that needs a single character from a dynamic value.
| // Get first letter of product title (use with Bricks dynamic data): echo bricks_get_first_char( get_the_title() ); // e.g. ‘S’ from ‘Shirt’ // In a Bricks Code element:bricks_get_first_char( get_the_title() ); |
| 💡 Tip: Combine bricks_get_first_char with the {current_user_field:name} dynamic tag approach inside a Code element to render user avatar initials: bricks_get_first_char( wp_get_current_user()->display_name ) |

