Filter: wpd_ai_custom_product_cost_options
Register or modify the list of custom product cost types (e.g. packaging, fulfillment) that can be applied per product. Each option can have a static fee and/or a percentage of sell price.
Description
Alpha Insights supports custom cost types in addition to built-in cost and shipping. This filter receives the array of registered custom product cost options (keyed by slug). Each option is an array with keys such as label, static_fee, percent_of_sell_price. Product-specific values are stored in post meta _wpd_ai_custom_product_costs. Add new cost types here so they appear in the product edit screen and in profit calculations.
Location
File: includes/functions/wpd-custom-cost-functions.php
Function: Used when retrieving custom product cost options (e.g. wpdai_get_custom_product_cost_options() or similar).
Parameters
| Parameter | Type | Description |
|---|---|---|
| $custom_product_costs | array | Associative array slug => array( ‘label’ => string, ‘static_fee’ => float, ‘percent_of_sell_price’ => float, … ). Defaults from settings or empty. |
| $product_id | int | Product ID (may be 0 when building the global list) |
Return
Type: array
The (possibly modified) array of custom product cost options. Keys are slugs; values are arrays with at least label and optionally static_fee, percent_of_sell_price.
Example Usage
Register a new custom cost type
add_filter( 'wpd_ai_custom_product_cost_options', 'register_packaging_cost', 10, 2 );
function register_packaging_cost( $custom_product_costs, $product_id ) {
$custom_product_costs['packaging'] = array(
'label' => __( 'Packaging', 'alpha-insights-pro' ),
'static_fee' => 0,
'percent_of_sell_price' => 0,
);
return $custom_product_costs;
}
Add fulfillment fee option
add_filter( 'wpd_ai_custom_product_cost_options', 'add_fulfillment_cost_option', 10, 2 );
function add_fulfillment_cost_option( $custom_product_costs, $product_id ) {
if ( ! isset( $custom_product_costs['fulfillment'] ) ) {
$custom_product_costs['fulfillment'] = array(
'label' => __( 'Fulfillment', 'alpha-insights-pro' ),
'static_fee' => 0,
'percent_of_sell_price' => 0,
);
}
return $custom_product_costs;
}
Related
- wpd_ai_custom_product_cost_default_value – Default value for a custom product cost
- wpd_ai_custom_order_cost_default_value – Custom order-level costs
- wpd_ai_calculate_cost_profit_by_order – Full profit calculation