Modify the final formatted price HTML output used throughout Alpha Insights.
This filter allows you to customize the final HTML markup for prices displayed in Alpha Insights reports, dashboards, and admin interfaces. Similar to WooCommerce's wc_price filter but specific to Alpha Insights price formatting.
File: includes/wpd-functions.php
Function: wpd_store_price()
Line: ~1193
| Parameter | Type | Description |
|---|---|---|
| $return | string | The complete HTML markup for the price |
| $price | string | The formatted numeric price string |
| $args | array | Formatting arguments (currency, decimals, separators, etc.) |
| $unformatted_price | float | The raw unformatted price value |
| $original_price | float|string | The original price before any processing |
Type: string
Description: Modified price HTML markup
$args = array(
'ex_tax_label' => false, // Show "ex. VAT" label
'currency' => 'USD', // Currency code
'decimal_separator' => '.', // Decimal separator
'thousand_separator' => ',', // Thousand separator
'decimals' => 2, // Number of decimals
'price_format' => '%1$s%2$s' // Symbol/price format
);
add_filter( 'wpd_price', 'color_code_prices', 10, 5 );
function color_code_prices( $return, $price, $args, $unformatted_price, $original_price )
{
// Color negative values red, positive green
if ( $unformatted_price < 0 )
{
$return = '' . $return . '';
}
elseif ( $unformatted_price > 0 )
{
$return = '' . $return . '';
}
return $return;
}
add_filter( 'wpd_price', 'add_price_tooltips', 10, 5 );
function add_price_tooltips( $return, $price, $args, $unformatted_price, $original_price )
{
// If currency was converted, show original
$base_currency = get_option( 'woocommerce_currency' );
if ( $args['currency'] !== $base_currency )
{
$original_formatted = wc_price( $original_price, array( 'currency' => $base_currency ) );
$return = sprintf(
'%s',
esc_attr( strip_tags( $original_formatted ) ),
$return
);
}
return $return;
}
add_filter( 'wpd_price', 'add_price_classes', 10, 5 );
function add_price_classes( $return, $price, $args, $unformatted_price, $original_price )
{
$classes = array( 'wpd-price' );
// Add value-based classes
if ( $unformatted_price < 0 )
{
$classes[] = 'negative-value';
}
elseif ( $unformatted_price > 0 )
{
$classes[] = 'positive-value';
}
else
{
$classes[] = 'zero-value';
}
// Add magnitude classes
if ( abs( $unformatted_price ) > 10000 )
{
$classes[] = 'large-amount';
}
elseif ( abs( $unformatted_price ) > 1000 )
{
$classes[] = 'medium-amount';
}
else
{
$classes[] = 'small-amount';
}
// Wrap with classes
return '' . $return . '';
}
add_filter( 'wpd_price', 'abbreviate_large_prices', 10, 5 );
function abbreviate_large_prices( $return, $price, $args, $unformatted_price, $original_price )
{
// Only abbreviate very large numbers
if ( abs( $unformatted_price ) >= 1000000 )
{
$abbreviated = abs( $unformatted_price ) / 1000000;
$symbol = wpd_get_woocommerce_currency_symbol( $args['currency'] );
$sign = $unformatted_price < 0 ? '-' : '';
$return = sprintf(
'%s%s%.1fM',
esc_attr( strip_tags( $return ) ), // Full price in tooltip
$sign,
$symbol,
$abbreviated
);
}
elseif ( abs( $unformatted_price ) >= 1000 )
{
$abbreviated = abs( $unformatted_price ) / 1000;
$symbol = wpd_get_woocommerce_currency_symbol( $args['currency'] );
$sign = $unformatted_price < 0 ? '-' : '';
$return = sprintf(
'%s%s%.1fK',
esc_attr( strip_tags( $return ) ),
$sign,
$symbol,
$abbreviated
);
}
return $return;
}
add_filter( 'wpd_price', 'add_trend_icons', 10, 5 );
function add_trend_icons( $return, $price, $args, $unformatted_price, $original_price )
{
// Add up/down arrow icons
if ( $unformatted_price > 0 )
{
$return = '↑ ' . $return;
}
elseif ( $unformatted_price < 0 )
{
$return = '↓ ' . $return;
}
return $return;
}
add_filter( 'wpd_price', 'custom_report_format', 10, 5 );
function custom_report_format( $return, $price, $args, $unformatted_price, $original_price )
{
// Only apply in report context
if ( ! isset( $_GET['page'] ) || strpos( $_GET['page'], 'reports' ) === false )
{
return $return;
}
// Add custom wrapper for reports
$return = sprintf(
'%s',
esc_attr( $unformatted_price ),
$return
);
return $return;
}
add_filter( 'wpd_price', 'add_data_attributes', 10, 5 );
function add_data_attributes( $return, $price, $args, $unformatted_price, $original_price )
{
// Add data attributes for JavaScript manipulation
$return = str_replace(
'
/* Add in your theme or plugin CSS */
.wpd-price.negative-value {
color: #dc3545;
font-weight: 600;
}
.wpd-price.positive-value {
color: #28a745;
}
.wpd-price.large-amount {
font-size: 1.2em;
font-weight: bold;
}
.abbreviated-price {
cursor: help;
border-bottom: 1px dotted currentColor;
}
add_filter( 'wpd_price', 'debug_price_filter', 999, 5 );
function debug_price_filter( $return, $price, $args, $unformatted_price, $original_price )
{
error_log( sprintf(
'Price Display - Unformatted: %s | Formatted: %s | Currency: %s',
$unformatted_price,
$price,
$args['currency']
));
return $return;
}
raw_woocommerce_price - Filter raw price before formattingformatted_woocommerce_price - Filter numeric formatted pricewoocommerce_price_trim_zeros - Control zero trimmingwpd_store_price( $price, $args ) - Format price for displaywpd_get_woocommerce_currency_symbol( $currency ) - Get currency symbol