## Filter: wpd_ai_custom_product_cost_options

This filter allows developers to programmatically register custom product cost options that appear in the product edit screen.

### Description

Use this filter to add custom cost types to products (beyond the standard COGS). Custom product costs can be static fees, percentages of sell price, or both combined.

#### Location

File:`includes/functions/wpd-custom-cost-functions.php`

Function:`wpd_get_custom_product_cost_options()`

### Parameters

Parameter | Type | Description
--- | --- | ---
$custom_product_costs | array | Existing array of custom product costs (initially empty or from settings)
$product_id | int | The ID of the product being edited

#### Return

Type: array

Description: Associative array of custom product cost options

### Array Structure

    array(
        'unique_slug' => array(
            'label' => 'Display Label',
            'description' => 'Helper text for admin',
            'placeholder' => '0.00',
            'static_fee' => 5.00, // Fixed amount per unit
            'percent_of_sell_price' => 10.5 // Percentage of sell price
        )
    )

#### Example Usage

### Add Packaging Cost Option

    add_filter( 'wpd_ai_custom_product_cost_options', 'my_custom_product_costs', 10, 2 );

    function my_custom_product_costs( $custom_costs, $product_id ) {
        // Add packaging cost option
        $custom_costs['packaging_cost'] = array(
            'label' => 'Packaging Cost',
            'description' => 'Cost of packaging materials for this product',
            'placeholder' => '2.50',
            'static_fee' => 2.50, // Default $2.50 per unit
            'percent_of_sell_price' => 0 // Not percentage-based
        );

        return $custom_costs;
    }

### Add Shipping Supplies Cost

    add_filter( 'wpd_ai_custom_product_cost_options', 'add_shipping_supplies_cost', 10, 2 );

    function add_shipping_supplies_cost( $custom_costs, $product_id ) {
        $custom_costs['shipping_supplies'] = array(
            'label' => 'Shipping Supplies',
            'description' => 'Boxes, tape, packing materials',
            'placeholder' => '0.00',
            'static_fee' => 3.00,
            'percent_of_sell_price' => 0
        );

        return $custom_costs;
    }

### Add Labor Cost (Percentage-Based)

    add_filter( 'wpd_ai_custom_product_cost_options', 'add_labor_cost', 10, 2 );

    function add_labor_cost( $custom_costs, $product_id ) {
        // Labor cost as 15% of sell price
        $custom_costs['labor_cost'] = array(
            'label' => 'Labor Cost',
            'description' => 'Assembly and quality control labor',
            'placeholder' => '0.00',
            'static_fee' => 0,
            'percent_of_sell_price' => 15.0 // 15% of sell price
        );

        return $custom_costs;
    }

### Combined Static + Percentage

    add_filter( 'wpd_ai_custom_product_cost_options', 'add_fulfillment_cost', 10, 2 );

    function add_fulfillment_cost( $custom_costs, $product_id ) {
        // $5 base + 3% of price
        $custom_costs['fulfillment_fee'] = array(
            'label' => '3PL Fulfillment Fee',
            'description' => 'Third-party fulfillment center fee',
            'placeholder' => '0.00',
            'static_fee' => 5.00, // $5 base fee
            'percent_of_sell_price' => 3.0 // + 3% of price
        );

        return $custom_costs;
    }

### Product-Specific Logic

    add_filter( 'wpd_ai_custom_product_cost_options', 'conditional_custom_costs', 10, 2 );

    function conditional_custom_costs( $custom_costs, $product_id ) {
        // Only add custom assembly cost for specific category
        $product = wc_get_product( $product_id );

        if ( $product && $product->is_type('variable') ) {
            // Variable products get assembly cost
            $custom_costs['assembly_cost'] = array(
                'label' => 'Custom Assembly',
                'description' => 'Required for customizable products',
                'static_fee' => 15.00,
                'percent_of_sell_price' => 0
            );
        }

        return $custom_costs;
    }

#### Field Definitions

### label (string, required)

Display name shown in product edit screen

#### description (string, optional)

Helper text displayed below the input field

### placeholder (string/float, optional)

Placeholder text in the input field

#### static_fee (float, optional)

Fixed dollar amount added per unit. Set to `null` or `0` if not used.

### percent_of_sell_price (float, optional)

Percentage of product sell price (0-100). Set to `null` or `0` if not used.

### Calculation Logic

For each unit sold, the custom cost calculated as:

    Cost = (Sell Price Ã— (percent_of_sell_price / 100)) + static_fee

Example with $50 product:

- static_fee = $5
- percent_of_sell_price = 10
- Cost = ($50 Ã— 0.10) + $5 = $10

### Where Costs Appear

Once registered, custom costs:

- Appear in product edit screen (WooCommerce → Products → Edit)
- Can be set per product or per variation
- Are included in profit calculations automatically
- Show in Cost of Goods Manager
- Appear in order profit breakdowns

### Best Practices

- Use unique, descriptive slugs (e.g., 'packaging_cost' not 'cost1')
- Provide helpful descriptions for store admins
- Set reasonable default values
- Use either static_fee OR percent_of_sell_price, or both
- Test with variable products to ensure compatibility

### Notes

- Filter runs every time product costs are fetched
- Results are cached per product for performance
- Can register multiple custom costs (each with unique slug)
- Custom costs are optional - users can leave them blank

### Related Filters

- wpd_ai_custom_product_cost_default_value- Filter default value per line item
- wpd_ai_custom_order_cost_default_value- Order-level custom costs

### Related Functions

- `wpd_get_custom_product_cost_options( $product_id )`- Retrieve custom costs for a product
- `wpd_get_additional_costs_by_product_id( $product_id )`- Get calculated custom costs