Hooks for UI and Info Blocks
Filters for modifying discount display on product pages and in the cart.
Modifying the Info Block Label
Section titled “Modifying the Info Block Label”This filter allows you to modify the label (discount name) in the info block.
apply_filters( 'wpify_woo_discounts_info_block_item_label', $label, $rule, $product );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$label | string | Label text (rule name) |
$rule | array | Array with rule settings |
$product | WC_Product | Current product |
Usage Example
Section titled “Usage Example”Adding Emoji Based on Discount Type
Section titled “Adding Emoji Based on Discount Type”/** * Add emoji to label based on discount type * * @param string $label Label text * @param array $rule Rule * @param WC_Product $product Product * * @return string */function add_emoji_to_label( $label, $rule, $product ): string { $emoji = match ( $rule['rule_type'] ?? '' ) { 'bulk' => '📦 ', 'bundle' => '🎁 ', 'free_gift' => '🎀 ', 'buy_x_get_x' => '🔥 ', default => '💰 ', };
return $emoji . $label;}add_filter( 'wpify_woo_discounts_info_block_item_label', 'add_emoji_to_label', 10, 3 );Modifying Info Block Content
Section titled “Modifying Info Block Content”This filter allows you to modify the info block content (message and countdown) on the product page.
apply_filters( 'wpify_woo_discounts_info_block_item_content', $content, $rule, $product );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$content | string | HTML content (message + countdown) |
$rule | array | Array with rule settings |
$product | WC_Product | Current product |
Usage Examples
Section titled “Usage Examples”Adding Custom Text
Section titled “Adding Custom Text”/** * Add free shipping information to the info block * * @param string $content HTML content * @param array $rule Rule * @param WC_Product $product Product * * @return string */function add_free_shipping_info( $content, $rule, $product ): string { $content .= '<p class="free-shipping-note">+ free shipping on orders over $50</p>'; return $content;}add_filter( 'wpify_woo_discounts_info_block_item_content', 'add_free_shipping_info', 10, 3 );Conditional Content Based on Rule Type
Section titled “Conditional Content Based on Rule Type”/** * Add badge based on discount type * * @param string $content HTML content * @param array $rule Rule * @param WC_Product $product Product * * @return string */function add_discount_badge( $content, $rule, $product ): string { $badge = '';
switch ( $rule['rule_type'] ?? '' ) { case 'bulk': $badge = '<span class="discount-badge bulk">Volume Discount</span>'; break; case 'bundle': $badge = '<span class="discount-badge bundle">Bundle Discount</span>'; break; case 'buy_x_get_x': case 'buy_x_get_y': $badge = '<span class="discount-badge bogo">BOGO Deal</span>'; break; }
return $badge . $content;}add_filter( 'wpify_woo_discounts_info_block_item_content', 'add_discount_badge', 10, 3 );Modifying the Pricing Table
Section titled “Modifying the Pricing Table”This filter allows you to modify the HTML output of the pricing table (for bulk/bundle discounts).
apply_filters( 'wpify_woo_discounts_info_block_item_pricing', $html, $rule, $product );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$html | string | Pricing table HTML |
$rule | array | Rule settings (since v1.0.2 contains only valid subrules) |
$product | WC_Product | Current product |
Usage Examples
Section titled “Usage Examples”Adding a Table Header
Section titled “Adding a Table Header”/** * Add a custom header above the pricing table * * @param string $html Table HTML * @param array $rule Rule * @param WC_Product $product Product * * @return string */function add_pricing_table_header( $html, $rule, $product ): string { $header = '<h4 class="pricing-table-title">The more you buy, the more you save!</h4>'; return $header . $html;}add_filter( 'wpify_woo_discounts_info_block_item_pricing', 'add_pricing_table_header', 10, 3 );Hiding the Table for Certain Products
Section titled “Hiding the Table for Certain Products”/** * Hide pricing table for products in the "clearance" category * * @param string $html Table HTML * @param array $rule Rule * @param WC_Product $product Product * * @return string */function hide_pricing_for_clearance( $html, $rule, $product ): string { if ( has_term( 'vyprodej', 'product_cat', $product->get_id() ) ) { return ''; // Hide table } return $html;}add_filter( 'wpify_woo_discounts_info_block_item_pricing', 'hide_pricing_for_clearance', 10, 3 );Modifying the Entire Info Block
Section titled “Modifying the Entire Info Block”This filter allows you to modify the complete arguments for the info block template.
apply_filters( 'wpify_woo_discounts_info_block_args', $args, $product );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$args | array | Template arguments |
$product | WC_Product | Current product |
Structure of $args
Section titled “Structure of $args”$args = array( 'items' => array( array( 'label' => '...', // Label text (rule name) 'content' => '...', // HTML content (message + countdown) 'pricing' => '...', // Pricing table HTML 'rule' => array(), // Rule data ), // more items... ), 'classes' => array( 'block' => array( 'wpify-woo-discount-info-block' ), 'item' => array( 'wpify-woo-discount-info-block__item' ), 'label' => array( 'wpify-woo-discount-info-block__label' ), 'content' => array( 'wpify-woo-discount-info-block__content' ), 'pricing' => array( 'wpify-woo-discount-info-block__pricing' ), ), 'product' => WC_Product,);Usage Examples
Section titled “Usage Examples”Adding a Custom CSS Class
Section titled “Adding a Custom CSS Class”/** * Add a custom CSS class to the info block * * @param array $args Template arguments * @param WC_Product $product Product * * @return array */function add_custom_class_to_info_block( $args, $product ): array { $args['classes']['block'][] = 'my-custom-discount-block';
// Add class based on product category if ( has_term( 'premium', 'product_cat', $product->get_id() ) ) { $args['classes']['block'][] = 'premium-product-discount'; }
return $args;}add_filter( 'wpify_woo_discounts_info_block_args', 'add_custom_class_to_info_block', 10, 2 );Sorting Items by Priority
Section titled “Sorting Items by Priority”/** * Sort info block items by rule priority * * @param array $args Template arguments * @param WC_Product $product Product * * @return array */function sort_info_block_items( $args, $product ): array { usort( $args['items'], function( $a, $b ) { $priority_a = $a['rule']['priority'] ?? 10; $priority_b = $b['rule']['priority'] ?? 10; return $priority_a - $priority_b; } );
return $args;}add_filter( 'wpify_woo_discounts_info_block_args', 'sort_info_block_items', 10, 2 );Limiting the Number of Displayed Discounts
Section titled “Limiting the Number of Displayed Discounts”/** * Display a maximum of 2 discounts on the product page * * @param array $args Template arguments * @param WC_Product $product Product * * @return array */function limit_displayed_discounts( $args, $product ): array { if ( count( $args['items'] ) > 2 ) { $args['items'] = array_slice( $args['items'], 0, 2 ); } return $args;}add_filter( 'wpify_woo_discounts_info_block_args', 'limit_displayed_discounts', 10, 2 );Breaking Change in v1.0.1
Section titled “Breaking Change in v1.0.1”The $rule parameter in UI filters is now a rule settings array, previously it was a subrule array. If you use these filters, verify compatibility.
Product Badge Hooks
Section titled “Product Badge Hooks”Filters for modifying product badges.
Modifying the Badge List
Section titled “Modifying the Badge List”This filter allows you to modify the list of badges for a product.
apply_filters( 'wpify_woo_discounts_product_badges', $badges, $product );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$badges | array | Array of badges for the product |
$product | WC_Product | Current product |
Example: Adding a Custom Badge
Section titled “Example: Adding a Custom Badge”/** * Add a "Bestseller" badge for products with high sales * * @param array $badges Array of badges * @param WC_Product $product Product * * @return array */function add_bestseller_badge( $badges, $product ): array { $total_sales = $product->get_total_sales();
if ( $total_sales > 100 ) { $badges[] = array( 'type' => 'custom', 'label' => 'Bestseller', 'class' => 'bestseller-badge', ); }
return $badges;}add_filter( 'wpify_woo_discounts_product_badges', 'add_bestseller_badge', 10, 2 );Modifying Badge HTML
Section titled “Modifying Badge HTML”This filter allows you to modify the resulting badge HTML.
apply_filters( 'wpify_woo_discounts_product_badges_html', $html, $badges, $product );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$html | string | Badge HTML output |
$badges | array | Array of badges |
$product | WC_Product | Current product |
Modifying Badge Text
Section titled “Modifying Badge Text”This filter allows you to modify the badge text including placeholders.
apply_filters( 'wpify_woo_discounts_badge_text', $result, $replacements, $label, $data );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$result | string | Resulting text after replacements |
$replacements | array | Replacement array ({discount}, {price}, etc.) |
$label | string | Original label template |
$data | array | Badge data |
Example: Custom Placeholder
Section titled “Example: Custom Placeholder”/** * Add a custom {stock} placeholder for stock quantity * * @param string $result Resulting text * @param array $replacements Replacement array * @param string $label Template * @param array $data Data * * @return string */function add_stock_placeholder( $result, $replacements, $label, $data ): string { if ( isset( $data['product'] ) && strpos( $label, '{stock}' ) !== false ) { $stock = $data['product']->get_stock_quantity() ?? 0; $result = str_replace( '{stock}', $stock, $result ); } return $result;}add_filter( 'wpify_woo_discounts_badge_text', 'add_stock_placeholder', 10, 4 );Skipping Badge Injection
Section titled “Skipping Badge Injection”This filter allows you to disable automatic badge injection.
apply_filters( 'wpify_woo_discounts_skip_badge_injection', $skip );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$skip | bool | Default false, return true to skip |
Example: Disabling on a Specific Page
Section titled “Example: Disabling on a Specific Page”/** * Disable badges on the "clearance" page * * @param bool $skip Skip injection * * @return bool */function skip_badges_on_clearance( $skip ): bool { if ( is_page( 'vyprodej' ) ) { return true; } return $skip;}add_filter( 'wpify_woo_discounts_skip_badge_injection', 'skip_badges_on_clearance' );Modifying Badge CSS
Section titled “Modifying Badge CSS”This filter allows you to modify the generated CSS for badges.
apply_filters( 'wpify_woo_discounts_badge_css', $css );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$css | string | CSS string |
New Product Detection
Section titled “New Product Detection”This filter allows you to modify the logic for determining a “new” product.
apply_filters( 'wpify_woo_discounts_is_product_new', $is_new, $product, $days );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$is_new | bool | Whether the product is new (default: published within $days days) |
$product | WC_Product | Product |
$days | int | Number of days for “new” |
Gallery Selectors for Single Product
Section titled “Gallery Selectors for Single Product”This filter allows you to add custom CSS selectors for detecting the product gallery on the product page.
apply_filters( 'wpify_woo_discounts_badge_gallery_selectors', $selectors );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$selectors | array | Array of CSS selectors |
Example: Adding a Selector for a Custom Theme
Section titled “Example: Adding a Selector for a Custom Theme”/** * Add selector for a custom theme * * @param array $selectors CSS selectors * * @return array */function add_my_theme_gallery_selector( $selectors ): array { $selectors[] = '.my-theme-product-gallery'; return $selectors;}add_filter( 'wpify_woo_discounts_badge_gallery_selectors', 'add_my_theme_gallery_selector' );Product Badge Module Initialization
Section titled “Product Badge Module Initialization”This action fires when the Product Badge module is initialized.
do_action( 'wpify_woo_discounts_product_badge_init', $module );Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
$module | ProductBadgeModule | Module instance |
Countdown Badge Integration
Section titled “Countdown Badge Integration”This filter allows you to add a countdown badge from the Countdown module or a custom solution.
apply_filters( 'wpify_woo_discounts_countdown_badge', $badge, $product );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$badge | array|null | Badge data (null = do not display) |
$product | WC_Product | Current product |
Badge Structure
Section titled “Badge Structure”$badge = array( 'type' => 'countdown', // Badge type for CSS class 'text' => '2:30:45', // Text displayed on badge);Example: Custom Countdown Badge
Section titled “Example: Custom Countdown Badge”/** * Add countdown badge for limited-time products * * @param array|null $badge Existing badge * @param WC_Product $product Product * * @return array|null */function add_custom_countdown_badge( $badge, $product ): ?array { $end_date = get_post_meta( $product->get_id(), '_sale_end_date', true );
if ( ! $end_date ) { return $badge; }
$remaining = strtotime( $end_date ) - time(); if ( $remaining <= 0 ) { return $badge; }
$hours = floor( $remaining / 3600 ); $minutes = floor( ( $remaining % 3600 ) / 60 );
return array( 'type' => 'countdown', 'text' => sprintf( '%d:%02d', $hours, $minutes ), );}add_filter( 'wpify_woo_discounts_countdown_badge', 'add_custom_countdown_badge', 10, 2 );Manual Select Hooks
Section titled “Manual Select Hooks”Filters for modifying the selection block (free gift, BOGO).
Selection Display Position
Section titled “Selection Display Position”This filter allows you to modify the positions where the selection block is displayed.
apply_filters( 'wpify_woo_discounts_selection_hooks', $hooks_map );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$hooks_map | array | Map of positions and WooCommerce hooks |
Example: Adding a Custom Position
Section titled “Example: Adding a Custom Position”/** * Add a custom position for the selection block * * @param array $hooks_map Hooks map * * @return array */function add_custom_selection_position( $hooks_map ): array { $hooks_map['my_custom_position'] = array( 'hook' => 'my_theme_after_cart', 'priority' => 10, ); return $hooks_map;}add_filter( 'wpify_woo_discounts_selection_hooks', 'add_custom_selection_position' );Modifying Selection Block Data
Section titled “Modifying Selection Block Data”This filter allows you to modify the data for the selection block template.
apply_filters( 'wpify_woo_discounts_selection_html_data', $data );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$data | array | Template data (CSS classes, texts) |
Modifying Selection Item Data
Section titled “Modifying Selection Item Data”This filter allows you to modify the data of an individual item in the selection.
apply_filters( 'wpify_woo_discounts_selection_html_item_data', $item_data, $product, $settings, $hidden_elements );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$item_data | array | Item data (image, name, etc.) |
$product | WC_Product | Product |
$settings | array | Manual Select group settings |
$hidden_elements | array | List of hidden elements |
Modifying Selection Item Price
Section titled “Modifying Selection Item Price”This filter allows you to modify the price display in the selection block.
apply_filters( 'wpify_woo_discounts_selection_html_item_price_data', $price_data, $product, $rule );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$price_data | array | Price data (original, discount, final) |
$product | WC_Product | Product |
$rule | array | Rule data |
Upsell Bar Hooks
Section titled “Upsell Bar Hooks”Filters for modifying the progress bar (upsell bar).
Modifying Upsell Bar Data
Section titled “Modifying Upsell Bar Data”This filter allows you to modify the data for a specific upsell bar.
apply_filters( 'wpify_woo_discounts_upsell_bar_data', $data, $bar, $index );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$data | array | Bar data (progress, messages, goal) |
$bar | array | Bar settings |
$index | int | Bar index |
Example: Custom Message Based on Progress
Section titled “Example: Custom Message Based on Progress”/** * Modify message based on current progress * * @param array $data Bar data * @param array $bar Settings * @param int $index Index * * @return array */function custom_upsell_message( $data, $bar, $index ): array { $progress = $data['progress'] ?? 0;
if ( $progress >= 75 ) { $data['message'] = 'Almost there! ' . $data['message']; }
return $data;}add_filter( 'wpify_woo_discounts_upsell_bar_data', 'custom_upsell_message', 10, 3 );Modifying Upsell Bar CSS Classes
Section titled “Modifying Upsell Bar CSS Classes”This filter allows you to modify the CSS classes of the upsell bar wrapper.
apply_filters( 'wpify_woo_discounts_upsell_bar_wrapper_classes', $classes, $bar, $index );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$classes | array | Array of CSS classes |
$bar | array | Bar settings |
$index | int | Bar index |
Action Hooks
Section titled “Action Hooks”In addition to filters, action hooks are available for adding custom content.
Rendering Selection Blocks
Section titled “Rendering Selection Blocks”This action fires when rendering selection blocks in the cart.
do_action( 'wpify_woo_discounts_render_selections' );Usage Example
Section titled “Usage Example”/** * Add custom content before selection blocks */function add_content_before_selections(): void { echo '<div class="my-custom-selection-header">'; echo '<h3>Choose your gift</h3>'; echo '</div>';}add_action( 'wpify_woo_discounts_render_selections', 'add_content_before_selections', 5 );Rendering a Selection Item
Section titled “Rendering a Selection Item”This action fires when rendering an individual item in the selection block.
do_action( 'wpify_woo_discounts_selection_html_item', $product, $rule );Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
$product | WC_Product | Product |
$rule | array | Rule settings |
Usage Example
Section titled “Usage Example”/** * Add stock availability information to the item * * @param WC_Product $product Product * @param array $rule Rule */function add_stock_info_to_selection_item( $product, $rule ): void { $stock = $product->get_stock_quantity(); if ( $stock !== null && $stock < 5 ) { echo '<span class="low-stock-warning">Only ' . $stock . ' left in stock!</span>'; }}add_action( 'wpify_woo_discounts_selection_html_item', 'add_stock_info_to_selection_item', 10, 2 );Info Block Hooks in the Template
Section titled “Info Block Hooks in the Template”Action hooks are available in the info block template for adding custom content.
do_action( 'wpify_woo_discounts_info_block_html_before' );do_action( 'wpify_woo_discounts_info_block_html_after' );do_action( 'wpify_woo_discounts_info_block_html_item_before', $item, $product );do_action( 'wpify_woo_discounts_info_block_html_item_after', $item, $product );Parameters (for item hooks)
Section titled “Parameters (for item hooks)”| Parameter | Type | Description |
|---|---|---|
$item | array | Item data (content, pricing, rule) |
$product | WC_Product | Current product |
Usage Example
Section titled “Usage Example”/** * Add CTA button after info block */function add_cta_after_info_block(): void { echo '<a href="/akce" class="discount-cta-button">View all deals</a>';}add_action( 'wpify_woo_discounts_info_block_html_after', 'add_cta_after_info_block' );
/** * Add icon before each info block item * * @param array $item Item data * @param WC_Product $product Product */function add_icon_before_info_item( $item, $product ): void { $rule_type = $item['rule']['rule_type'] ?? ''; $icon = match( $rule_type ) { 'bulk' => '📦', 'bundle' => '🎁', default => '💰', }; echo '<span class="discount-icon">' . $icon . '</span>';}add_action( 'wpify_woo_discounts_info_block_html_item_before', 'add_icon_before_info_item', 10, 2 );Savings Summary Hooks
Section titled “Savings Summary Hooks”Action hooks are available in the Savings Summary template for adding custom content.
do_action( 'wpify_woo_discounts_savings_summary_start', $tracking, $total_saved );do_action( 'wpify_woo_discounts_savings_summary_end', $tracking, $total_saved );Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
$tracking | array | Discount tracking data |
$total_saved | float | Total saved amount |
Usage Example
Section titled “Usage Example”/** * Add motivational message before savings summary * * @param array $tracking Tracking data * @param float $total_saved Saved amount */function add_savings_motivation( $tracking, $total_saved ): void { if ( $total_saved > 500 ) { echo '<p class="savings-motivation">Great purchase! You saved more than $500!</p>'; }}add_action( 'wpify_woo_discounts_savings_summary_start', 'add_savings_motivation', 10, 2 );
/** * Add link to more deals after savings summary * * @param array $tracking Tracking data * @param float $total_saved Saved amount */function add_more_deals_link( $tracking, $total_saved ): void { echo '<a href="/akce" class="more-deals-link">View more deals →</a>';}add_action( 'wpify_woo_discounts_savings_summary_end', 'add_more_deals_link', 10, 2 );Upsell Cart Item Hooks
Section titled “Upsell Cart Item Hooks”Filters for modifying inline checkbox offers in cart item rows (Upsell in Cart Item mode).
Modifying Item Data
Section titled “Modifying Item Data”This filter allows you to modify the upsell item data before template rendering.
apply_filters( 'wpify_woo_discounts_upsell_cart_item_data', $item_data, $product, $rule, $cart_item_key );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$item_data | array | Item data (image, name, price, etc.) |
$product | WC_Product | Target product |
$rule | array | Rule settings |
$cart_item_key | string | Cart item key of the trigger product |
Example: Adding Custom Text
Section titled “Example: Adding Custom Text”/** * Add "FREE" badge to upsell items with 100% discount * * @param array $item_data Item data * @param WC_Product $product Product * @param array $rule Rule * @param string $key Cart item key * * @return array */function add_free_badge_to_upsell( $item_data, $product, $rule, $key ): array { $price_data = $item_data['price_data'] ?? []; if ( isset( $price_data['discounted_price'] ) && 0.0 === (float) $price_data['discounted_price'] ) { $item_data['item_title'] = '🎁 ' . $item_data['item_title']; } return $item_data;}add_filter( 'wpify_woo_discounts_upsell_cart_item_data', 'add_free_badge_to_upsell', 10, 4 );Modifying Price Data
Section titled “Modifying Price Data”This filter allows you to modify the price data of an upsell item.
apply_filters( 'wpify_woo_discounts_upsell_cart_item_price_data', $price_data, $product, $rule );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$price_data | array | Price data (original_price, discounted_price, discount_amount) |
$product | WC_Product | Target product |
$rule | array | Rule settings |
Modifying the Final HTML
Section titled “Modifying the Final HTML”This filter allows you to modify the complete HTML output of the upsell checkboxes for a given cart item.
apply_filters( 'wpify_woo_discounts_upsell_cart_item_html', $html, $cart_item, $cart_item_key );Filter Parameters
Section titled “Filter Parameters”| Parameter | Type | Description |
|---|---|---|
$html | string | Complete HTML of all upsell checkboxes |
$cart_item | array | Cart item data of the trigger product |
$cart_item_key | string | Cart item key |
Example: Wrapping in a Custom Wrapper
Section titled “Example: Wrapping in a Custom Wrapper”/** * Wrap upsell checkboxes in a custom wrapper * * @param string $html Checkbox HTML * @param array $cart_item Cart item * @param string $cart_item_key Cart item key * * @return string */function wrap_upsell_checkboxes( $html, $cart_item, $cart_item_key ): string { return '<div class="my-upsell-wrapper">' . $html . '</div>';}add_filter( 'wpify_woo_discounts_upsell_cart_item_html', 'wrap_upsell_checkboxes', 10, 3 );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.