This filter allows developers to programmatically register custom product cost options that appear in the product edit screen.
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.
File:includes/functions/wpd-custom-cost-functions.php
Function:wpd_get_custom_product_cost_options()
| 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 |
Type: array
Description: Associative array of custom product cost options
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
)
)
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_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_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;
}
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;
}
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;
}
Display name shown in product edit screen
Helper text displayed below the input field
Placeholder text in the input field
Fixed dollar amount added per unit. Set to null or 0 if not used.
Percentage of product sell price (0-100). Set to null or 0 if not used.
For each unit sold, the custom cost calculated as:
Cost = (Sell Price × (percent_of_sell_price / 100)) + static_fee
Example with $50 product:
Once registered, custom costs:
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