WooCommerce Compatibility Filters
Alpha Insights uses several standard WooCommerce filters to ensure compatibility and consistent behavior with WooCommerce core.
Overview
These are native WooCommerce filters that Alpha Insights respects and utilizes. They are documented here for reference when customizing price display and currency handling in Alpha Insights.
Filter: raw_woocommerce_price
Description
Filter the raw numeric price value before any formatting is applied. This is the first filter in the price formatting pipeline.
Location in Alpha Insights
File: includes/wpd-functions.php
Function: wpd_store_price()
Line: ~1158
Parameters
| Parameter | Type | Description |
|---|---|---|
| $raw_price | float | Raw price value (absolute value if negative) |
| $original_price | float|string | Original price before processing |
Example Usage
add_filter( 'raw_woocommerce_price', 'modify_raw_price', 10, 2 );
function modify_raw_price( $price, $original_price )
{
// Round to nearest dollar
if ( abs( $price ) > 100 )
{
return round( $price, 0 );
}
return $price;
}
Filter: formatted_woocommerce_price
Description
Filter the price after it has been formatted with thousands separators and decimal places, but before HTML markup is added.
Location in Alpha Insights
File: includes/wpd-functions.php
Function: wpd_store_price()
Line: ~1170
Parameters
| Parameter | Type | Description |
|---|---|---|
| $formatted_price | string | Formatted price string (e.g., “1,234.56”) |
| $price | float | Unformatted price value |
| $decimals | int | Number of decimal places |
| $decimal_separator | string | Decimal separator character |
| $thousand_separator | string | Thousand separator character |
| $original_price | float|string | Original price value |
Example Usage
add_filter( 'formatted_woocommerce_price', 'customize_formatted_price', 10, 6 );
function customize_formatted_price( $formatted, $price, $decimals, $dec_sep, $thou_sep, $original )
{
// Add custom thousand separator styling
$formatted = str_replace( $thou_sep, '' . $thou_sep . '', $formatted );
return $formatted;
}
Filter: woocommerce_price_trim_zeros
Description
Control whether trailing zeros after the decimal point should be removed from prices.
Location in Alpha Insights
File: includes/wpd-functions.php
Function: wpd_store_price()
Line: ~1172
Parameters
| Parameter | Type | Description |
|---|---|---|
| $trim_zeros | bool | Whether to trim trailing zeros (default: false) |
Example Usage
Enable Zero Trimming
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
Result:
- $10.00 becomes $10
- $15.50 stays $15.50
- $20.10 becomes $20.1
Conditional Zero Trimming
add_filter( 'woocommerce_price_trim_zeros', 'conditional_trim_zeros' );
function conditional_trim_zeros( $trim )
{
// Only trim zeros for whole dollar amounts
global $current_price;
if ( isset( $current_price ) && floor( $current_price ) == $current_price )
{
return true;
}
return false;
}
Filter: woocommerce_currency_symbols
Description
Modify the complete array of currency symbols used by WooCommerce and Alpha Insights.
Location in Alpha Insights
File: includes/functions/wpd-currency-functions.php
Function: wpd_get_woocommerce_currency_symbol()
Line: ~279
Parameters
| Parameter | Type | Description |
|---|---|---|
| $symbols | array | Associative array of currency codes to symbols |
Example Usage
Add Custom Currency
add_filter( 'woocommerce_currency_symbols', 'add_custom_currencies' );
function add_custom_currencies( $symbols )
{
// Add cryptocurrencies
$symbols['BTC'] = '฿';
$symbols['ETH'] = 'Ξ';
// Add custom internal currency
$symbols['CREDITS'] = 'CR';
// Modify existing symbol
$symbols['USD'] = 'US$';
return $symbols;
}
Replace All Symbols with Codes
add_filter( 'woocommerce_currency_symbols', 'use_currency_codes' );
function use_currency_codes( $symbols )
{
// Replace all symbols with their currency codes
foreach ( $symbols as $code => $symbol )
{
$symbols[$code] = $code;
}
return $symbols;
}
Important Compatibility Notes
Filter Priority
These filters are applied in this order during price formatting:
raw_woocommerce_price– Modify raw numberformatted_woocommerce_price– Modify formatted stringwoocommerce_price_trim_zeros– Trim zeros if enabledwpd_price– Final HTML output (Alpha Insights specific)
WooCommerce Compatibility
- These filters maintain compatibility with WooCommerce core
- Changes affect both WooCommerce and Alpha Insights
- Test in both WooCommerce frontend and Alpha Insights admin
- Some third-party WooCommerce plugins may also use these filters
Best Practices
- Use Alpha Insights specific filters (
wpd_*) when possible - Only use WooCommerce filters when you need global changes
- Test thoroughly with different price values and currencies
- Consider multi-currency plugin compatibility
- Document any modifications for future reference
Performance Considerations
- These filters run on EVERY price display
- Keep logic lightweight and fast
- Avoid database queries or API calls
- Cache results when possible
- Use early returns to minimize processing
Debugging All Price Filters
// Log all price filter stages
add_filter( 'raw_woocommerce_price', 'debug_raw_price', 999, 2 );
function debug_raw_price( $price, $original )
{
error_log( '1. Raw Price: ' . $price );
return $price;
}
add_filter( 'formatted_woocommerce_price', 'debug_formatted_price', 999, 6 );
function debug_formatted_price( $formatted, $price, $decimals, $dec_sep, $thou_sep, $original )
{
error_log( '2. Formatted Price: ' . $formatted );
return $formatted;
}
add_filter( 'wpd_price', 'debug_final_price', 999, 5 );
function debug_final_price( $return, $price, $args, $unformatted, $original )
{
error_log( '3. Final HTML: ' . $return );
return $return;
}
Related Alpha Insights Filters
- wpd_price – Alpha Insights specific price HTML filter
- wpd_woocommerce_currency_symbol – Alpha Insights specific symbol filter
WooCommerce Documentation
For more information about these filters, see: