Filter: wpd_ai_cost_price_support_woocommerce_native_cogs

Control whether Alpha Insights should check for and use WooCommerce's native Cost of Goods Sold (COGS) plugin data when retrieving product costs.

Description

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.

Location

File: includes/wpd-functions.php

Function: wpd_get_default_cost_price_by_product_id()

Line: ~326

Parameters

Parameter Type Description
$support_native_cogs bool Whether to check for WooCommerce native COGS data (default: true)

Return

Type: bool

Description: True to support native COGS, false to disable

Example Usage

Disable Native COGS Support

add_filter( 'wpd_ai_cost_price_support_woocommerce_native_cogs', '__return_false' );

Conditional Support Based on Plugin Availability

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;
}

Disable for Specific Products

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;
}

Best Practices

How It Works

When enabled (default), Alpha Insights checks for cost data in this order:

  1. Alpha Insights custom cost fields (highest priority)
  2. WooCommerce native COGS meta fields (if this filter returns true)
  3. Default cost value (0 if nothing found)

When disabled, Alpha Insights only checks:

  1. Alpha Insights custom cost fields
  2. Default cost value (0 if nothing found)

Compatible Plugins

This filter works with plugins that store cost data in standard WooCommerce meta fields, including: