Control whether Alpha Insights should check for and use WooCommerce's native Cost of Goods Sold (COGS) plugin data when retrieving product costs.
If you're using WooCommerce's official Cost of Goods Sold plugin or a compatible plugin that stores cost data in WooCommerce's standard meta fields, Alpha Insights can automatically detect and use that data. This filter allows you to enable or disable this integration.
File: includes/wpd-functions.php
Function: wpd_get_default_cost_price_by_product_id()
Line: ~326
| Parameter | Type | Description |
|---|---|---|
| $support_native_cogs | bool | Whether to check for WooCommerce native COGS data (default: true) |
Type: bool
Description: True to support native COGS, false to disable
add_filter( 'wpd_ai_cost_price_support_woocommerce_native_cogs', '__return_false' );
add_filter( 'wpd_ai_cost_price_support_woocommerce_native_cogs', 'conditional_native_cogs_support' );
function conditional_native_cogs_support( $support_native_cogs ) {
// Only support native COGS if WooCommerce COGS plugin is active
if ( class_exists( 'WC_COGS' ) ) {
return true;
}
return false;
}
add_filter( 'wpd_ai_cost_price_support_woocommerce_native_cogs', 'disable_native_cogs_for_specific_products' );
function disable_native_cogs_for_specific_products( $support_native_cogs ) {
// Check if we're in a context where we have a product ID
// This is a simplified example - actual implementation would need product context
if ( isset( $_GET['product_id'] ) ) {
$product_id = absint( $_GET['product_id'] );
// Disable for specific product categories
if ( has_term( 'custom-costing', 'product_cat', $product_id ) ) {
return false;
}
}
return $support_native_cogs;
}
When enabled (default), Alpha Insights checks for cost data in this order:
When disabled, Alpha Insights only checks:
This filter works with plugins that store cost data in standard WooCommerce meta fields, including:
add_filter( 'wpd_ai_cost_price_support_woocommerce_native_cogs', 'debug_native_cogs_support', 999 );
function debug_native_cogs_support( $support_native_cogs ) {
error_log( 'Alpha Insights Native COGS Support: ' . ( $support_native_cogs ? 'ENABLED' : 'DISABLED' ) );
return $support_native_cogs;
}
wpd_get_cost_price_by_product_id() - Retrieve product costwpd_get_default_cost_price_by_product_id() - Get default cost price