Wpd Ai Cost Price Support Woocommerce Native Cogs

Alpha Insights Documentation

Docs Navigation

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

  • Keep enabled (default) if using WooCommerce COGS plugin
  • Disable if you only want to use Alpha Insights cost fields
  • Use this filter to prioritize one cost source over another
  • Alpha Insights cost fields take precedence when both exist
  • This only affects cost retrieval, not cost storage

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:

  • WooCommerce Cost of Goods Sold (official)
  • Other COGS plugins using standard meta keys
  • Important Notes

    • Default is true – native COGS support is enabled by default
    • Alpha Insights cost fields always take priority over native COGS
    • Disabling this doesn’t affect existing cost data
    • This only affects cost retrieval, not storage
    • Use this filter if you want to use only Alpha Insights cost fields

    Debugging

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

Related Filters

Related Functions

  • wpd_get_cost_price_by_product_id() – Retrieve product cost
  • wpd_get_default_cost_price_by_product_id() – Get default cost price

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 Drag & Drop Report Builder.

5/5 – Trustpilot

Alpha Insights