Wpd Ai Cost Price Per Unit

Alpha Insights Documentation

Docs Navigation

Filter: wpd_ai_cost_price_per_unit

Filter the cost price per unit for a product before it is used in profit calculations.

Description

Alpha Insights calculates product cost from various sources (WooCommerce native COGS, product meta, default cost settings). This filter runs after that calculation so you can override or adjust the cost price per unit for a specific product. The value is cached per product for the request.

Location

File: includes/wpd-functions.php

Function: wpdai_get_cost_price_per_unit( $product_id )

Parameters

Parameter Type Description
$cost_price_per_unit float The calculated cost price per unit (before filter)
$product_id int WooCommerce product or variation ID

Return

Type: float

The cost price per unit to use (cast to float by the plugin).

Example Usage

Override cost from external system

add_filter( 'wpd_ai_cost_price_per_unit', 'my_custom_cost_from_erp', 10, 2 );
function my_custom_cost_from_erp( $cost_price_per_unit, $product_id ) {
    $erp_cost = get_post_meta( $product_id, '_my_erp_cost', true );
    if ( is_numeric( $erp_cost ) && $erp_cost >= 0 ) {
        return (float) $erp_cost;
    }
    return $cost_price_per_unit;
}

Apply a global markup to cost

add_filter( 'wpd_ai_cost_price_per_unit', 'add_safety_margin_to_cost', 10, 2 );
function add_safety_margin_to_cost( $cost_price_per_unit, $product_id ) {
    // Add 5% to cost for safety margin in profit reports
    return round( $cost_price_per_unit * 1.05, 4 );
}

Related Filters

Got A Question?

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Alpha Insights

Alpha Insights

The World's Most Advanced WooCommerce Profit Reporting Engine

5/5 – Trustpilot

Alpha Insights