Get Plugin
DocsSmart Input PricingHooks and Filters

Hooks and Filters

Customize Smart Input Pricing behavior with WordPress hooks and filters.

Smart Input Pricing provides several hooks and filters for developers to customize its behavior.

Filters

sip_price_per_unit

Modify the price per unit dynamically.

add_filter( 'sip_price_per_unit', function( $price, $product_id, $mode ) {
    // Double the price for a specific product
    if ( $product_id === 123 ) {
        return $price * 2;
    }
    return $price;
}, 10, 3 );
  • $price (float) - The current price per unit
  • $product_id (int) - The product ID
  • $mode (string) - The pricing mode (character, word, line)

sip_calculated_price

Modify the final calculated price.

add_filter( 'sip_calculated_price', function( $total, $count, $price_per_unit, $product_id ) {
    // Add a minimum fee
    return max( $total, 5.00 );
}, 10, 4 );
  • $total (float) - The calculated total
  • $count (int) - The unit count (characters, words, or lines)
  • $price_per_unit (float) - Price per unit
  • $product_id (int) - The product ID

sip_input_label

Customize the input field label.

add_filter( 'sip_input_label', function( $label, $product_id ) {
    return 'Enter your personalization text:';
}, 10, 2 );

sip_count_spaces

Control whether spaces count as characters.

add_filter( 'sip_count_spaces', function( $count_spaces, $product_id ) {
    return false; // Don't count spaces
}, 10, 2 );

sip_min_limit

Dynamically set minimum limit.

add_filter( 'sip_min_limit', function( $min, $product_id, $mode ) {
    // Require at least 3 characters for engraving products
    if ( has_term( 'engraving', 'product_cat', $product_id ) ) {
        return 3;
    }
    return $min;
}, 10, 3 );

sip_max_limit

Dynamically set maximum limit.

add_filter( 'sip_max_limit', function( $max, $product_id, $mode ) {
    return 100; // Global maximum
}, 10, 3 );

Actions

sip_before_input

Fires before the input field is rendered.

add_action( 'sip_before_input', function( $product_id ) {
    echo '<p class="input-instructions">Enter your custom text below:</p>';
}, 10, 1 );

sip_after_input

Fires after the input field is rendered.

add_action( 'sip_after_input', function( $product_id ) {
    echo '<p class="input-note">Special characters may not be supported.</p>';
}, 10, 1 );

sip_price_calculated

Fires when price is calculated (JavaScript callback available).

add_action( 'sip_price_calculated', function( $price, $count, $product_id ) {
    // Log pricing for analytics
    error_log( "SIP: Product $product_id - $count units = $price" );
}, 10, 3 );

JavaScript hooks

Client-side events

// Listen for price updates
document.addEventListener( 'sip_price_updated', function( event ) {
    console.log( 'New price:', event.detail.price );
    console.log( 'Unit count:', event.detail.count );
});

// Listen for validation errors
document.addEventListener( 'sip_validation_error', function( event ) {
    console.log( 'Error:', event.detail.message );
});

Custom validation

// Add custom validation
window.sipCustomValidation = function( text, mode, productId ) {
    // Block certain words
    if ( text.toLowerCase().includes( 'badword' ) ) {
        return {
            valid: false,
            message: 'This text contains prohibited words.'
        };
    }
    return { valid: true };
};

Examples

Tiered pricing

Charge less per character as count increases:

add_filter( 'sip_price_per_unit', function( $price, $product_id, $mode ) {
    // This runs on initial load, use calculated_price for dynamic tiers
    return $price;
}, 10, 3 );

add_filter( 'sip_calculated_price', function( $total, $count, $price_per_unit, $product_id ) {
    if ( $count > 50 ) {
        // 20% discount over 50 characters
        return $total * 0.8;
    }
    if ( $count > 25 ) {
        // 10% discount over 25 characters
        return $total * 0.9;
    }
    return $total;
}, 10, 4 );

Category-based pricing

Different rates for different categories:

add_filter( 'sip_price_per_unit', function( $price, $product_id, $mode ) {
    if ( has_term( 'premium', 'product_cat', $product_id ) ) {
        return $price * 1.5; // 50% more for premium
    }
    return $price;
}, 10, 3 );