Hooks for Integrations
Filters for adding support for custom plugins and integrations.
Custom Currency Conversion
Section titled “Custom Currency Conversion”If you use a custom multi-currency solution, you can add support using these filters.
Price Conversion
Section titled “Price Conversion”apply_filters( 'wpify_woo_discounts_convert_price', $converted, $price, $from_currency, $to_currency );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$converted | float|null | Converted price (null = use fallback) |
$price | float | Original price |
$from_currency | string | Source currency |
$to_currency | string | Target currency |
Usage Example
Section titled “Usage Example”/** * Custom currency conversion for a custom plugin * * @param float|null $converted Converted price * @param float $price Original price * @param string $from_currency Source currency * @param string $to_currency Target currency * * @return float|null */function custom_currency_conversion( $converted, $price, $from_currency, $to_currency ) { // Get exchange rate from a custom plugin $rate = my_currency_plugin_get_rate( $from_currency, $to_currency );
if ( $rate ) { return $price * $rate; }
return $converted; // Fallback to detected plugin}add_filter( 'wpify_woo_discounts_convert_price', 'custom_currency_conversion', 10, 4 );Custom Plugin Detection
Section titled “Custom Plugin Detection”apply_filters( 'wpify_woo_discounts_detect_currency_plugin', $detected );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$detected | string|null | Name of the detected plugin |
Usage Example
Section titled “Usage Example”/** * Register a custom currency plugin * * @param string|null $detected Detected plugin * * @return string|null */function detect_my_currency_plugin( $detected ) { if ( function_exists( 'my_currency_plugin_init' ) ) { return 'my_currency_plugin'; } return $detected;}add_filter( 'wpify_woo_discounts_detect_currency_plugin', 'detect_my_currency_plugin' );Text Field Translation
Section titled “Text Field Translation”Hooks for custom translation of message and label fields.
Discount Message Translation
Section titled “Discount Message Translation”apply_filters( 'wpify_woo_discounts_rule_message', $message, $rule );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$message | string | Discount message |
$rule | array | Rule data |
Discount Label Translation
Section titled “Discount Label Translation”apply_filters( 'wpify_woo_discounts_rule_label', $label, $rule );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$label | string | Discount label |
$rule | array | Rule data |
Example: Custom Translation
Section titled “Example: Custom Translation”/** * Translate message via a custom system * * @param string $message Message * @param array $rule Rule * * @return string */function translate_discount_message( $message, $rule ) { $rule_id = $rule['id'] ?? 0; $current_lang = my_get_current_language();
// Get translation from a custom table $translated = my_get_translation( 'discount_message', $rule_id, $current_lang );
return $translated ?: $message;}add_filter( 'wpify_woo_discounts_rule_message', 'translate_discount_message', 10, 2 );add_filter( 'wpify_woo_discounts_rule_label', 'translate_discount_message', 10, 2 );Claiming Cart Items (UCM Skip)
Section titled “Claiming Cart Items (UCM Skip)”Universal Cart Manager (UCM) iterates all cart items tagged with DISCOUNTED_PRODUCT_TYPE and recalculates prices on every cart event. External modules that own discount-style cart items (e.g. coupon-driven free gifts) can claim them so UCM does not touch them.
apply_filters( 'wpify_woo_discounts_ucm_skip_item', $skip, $cart_item_key, $cart_item );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$skip | bool | Whether to skip UCM lifecycle for this item. Default false. |
$cart_item_key | string | WC cart item key. |
$cart_item | array | The cart item array. |
Use Case
Section titled “Use Case”Return true when your module wants exclusive control over an item’s price and lifecycle (you set the price yourself via woocommerce_before_calculate_totals, handle removal yourself, etc.). UCM then ignores the item in change_discounted_prices().
add_filter( 'wpify_woo_discounts_ucm_skip_item', function ( $skip, $key, $item ) { if ( isset( $item['_my_module_marker'] ) ) { return true; } return $skip;}, 10, 3 );This is what the Coupons module uses internally for its Free Gift on Coupon items.
Where to Place the Code
Section titled “Where to Place the Code”You can add custom functions either in your child theme’s functions.php or using the Code Snippets plugin.