Configure the product post meta keys Alpha Insights checks when resolving a default per-unit cost price—after Alpha Insights' own _wpd_ai_product_cost field is empty.
When a product or variation has no cost saved in Alpha Insights' _wpd_ai_product_cost meta field, Alpha Insights loops through the meta keys returned by this filter on that product/variation ID. The first numeric value found is used as the per-unit COGS.
By default, Alpha Insights includes WooCommerce native COGS and several popular third-party COGS plugins so cost data is picked up automatically without extra configuration.
File: includes/wpd-functions.php
Function: wpdai_get_default_cost_price_by_product_id( $product_id )
Line: ~358
| Parameter | Type | Description |
|---|---|---|
| $meta_keys | array | Product post meta keys to check for per-unit COGS |
Type: array
Array of product post meta key strings. Each key is read via get_post_meta( $product_id, $key, true ) on the product or variation being resolved.
Alpha Insights passes this array as the filter default (first match wins):
| Meta key | Source |
|---|---|
_cogs_total_value |
WooCommerce native COGS (WooCommerce 10.0+) |
_wc_cog_cost |
WooCommerce Cost of Goods (official extension) |
_alg_wc_cog_cost |
Cost of Goods for WooCommerce by WP Factory |
_purchase_price |
ATUM Stock Management for WooCommerce (Stock Central) |
To disable a built-in source, remove its key from the array. To add your own integration, append additional keys—the earlier a key appears in the array, the higher its priority.
Product cost is resolved at two levels: order line items (per order) and products (catalog fallback). This filter affects the product fallback path only.
_wpd_ai_product_cogs on the line item (saved when the order is calculated)wpdai_get_cost_price_by_product_id() (see below)wpdai_get_cost_price_by_product_id())_wpd_ai_product_cost_price) — skips all lookups if this function already ran for the product in the current request_wpd_ai_product_cost on the product or variation (Alpha Insights product cost field)wpdai_get_default_cost_price_by_product_id() (see next section)0; child items carry costwpdai_get_default_cost_price_by_product_id()) — where this filter runsOnly evaluated when _wpd_ai_product_cost is empty on the product or variation.
wpd_ai_default_product_cost_price_meta_keys on the product/variation — first numeric value wins (defaults include Woo native and common plugin keys; see table above)_wpd_ai_product_cost0 if nothing else applies| Source | Takes precedence over | Notes |
|---|---|---|
Alpha Insights _wpd_ai_product_cost |
This filter, parent meta, general settings | Checked before wpdai_get_default_cost_price_by_product_id() runs |
| This filter (default meta keys) | Parent meta, general settings | First numeric key in the array wins; runs on the variation/product ID |
Parent _wpd_ai_product_cost and default meta keys |
General settings | Variation fallback only; parent is checked with the same meta key list from this filter |
wpd_ai_cost_price_per_unit |
All resolved product cost values | Runs after the full product resolution chain |
Line item _wpd_ai_product_cogs |
Product cost for that line item | Order-level; does not use this filter directly |
add_filter( 'wpd_ai_default_product_cost_price_meta_keys', 'wpd_ai_add_erp_cost_meta_key' );
function wpd_ai_add_erp_cost_meta_key( $meta_keys ) {
// Check ERP cost before built-in plugin keys
array_unshift( $meta_keys, '_my_erp_unit_cost' );
return $meta_keys;
}
add_filter( 'wpd_ai_default_product_cost_price_meta_keys', 'wpd_ai_append_supplier_cost_meta' );
function wpd_ai_append_supplier_cost_meta( $meta_keys ) {
$meta_keys[] = '_supplier_unit_cost';
return $meta_keys;
}
add_filter( 'wpd_ai_default_product_cost_price_meta_keys', 'wpd_ai_remove_native_cogs_meta_key' );
function wpd_ai_remove_native_cogs_meta_key( $meta_keys ) {
return array_values( array_diff( $meta_keys, array( '_cogs_total_value' ) ) );
}
add_filter( 'wpd_ai_default_product_cost_price_meta_keys', 'wpd_ai_custom_only_cost_meta_keys' );
function wpd_ai_custom_only_cost_meta_keys( $meta_keys ) {
return array( '_my_custom_unit_cost' );
}
_wpd_ai_product_cost then the same default meta key list_wpd_ai_line_item_cost_per_unit_meta_keys or wpd_ai_cost_price_per_unitwpdai_get_cost_price_by_product_id( $product_id ) – Primary product cost resolverwpdai_get_default_cost_price_by_product_id( $product_id ) – Default/fallback cost resolver (runs this filter)wpdai_get_default_cost_price_from_general_settings( $product_id ) – Percent-of-RRP fallback from settings