View Categories

Cost of Goods: Developer Hooks and Filters Reference

Cost of Goods: Product Cost & Profit Calculator for WooCommerce exposes a large set of filters and actions so you can adjust costs, profit, and behavior in code without editing plugin files. Every filter listed here fires inside the plugin’s own calculation and rendering paths, so a callback you register replaces or overrides the value the plugin would otherwise use.

All settings referenced below live under WPFactory > Cost of Goods (also reachable at WooCommerce > Settings > Cost of Goods). The plugin’s cost meta key is _alg_wc_cog_cost.

Hook prefix change in v4.1.6 #

In version 4.1.6 every hook and both shortcodes were renamed from the alg_wc_cog_* prefix to wpfcogs_*. The old names still work: the plugin registers forwarding aliases that pipe the new hook through the old name whenever a callback is attached to the old name. Each time an alias fires it calls _deprecated_hook( ..., '4.1.6', ... ), so you will see a deprecation notice in your debug log while WP_DEBUG is on. Migrate to the wpfcogs_* names; the migration table at the end lists the pairs.

Cost and profit value filters #

These are the filters most developers want. They fire on the value the plugin is about to use, so whatever you return wins.

Filter Filtered value Arguments
wpfcogs_get_product_cost A product’s cost of goods $cost, $product_id, $parent_id, $args
wpfcogs_get_product_handling_fee A product’s handling fee $fee, $product_id, $parent_id, $args
wpfcogs_order_item_cost The cost of a single order line item $cost, $product_id, $item_id, $item
wpfcogs_order_line_total An order line total used in the profit math $line_total, $order
wpfcogs_order_cost The total cost of an order $total_cost, $order
wpfcogs_order_profit The profit of an order $order_profit, $order
wpfcogs_order_total_taxes Order taxes used in profit $taxes, $order
wpfcogs_order_total_fees Order fees used in profit $fees, $order
wpfcogs_order_shipping_total Order shipping used in profit $shipping, $order
wpfcogs_order_total_refunded Refunded amount used in profit $refunded, $order
wpfcogs_order_net_payment The order’s net payment figure $net_payment, $order
wpfcogs_order_extra_cost_from_meta Extra order cost pulled from meta $cost, $order

Note that wpfcogs_order_total_for_pecentage_fees and wpfcogs_shipping_total_for_pecentage_fees also exist (the spelling of “pecentage” matches the source exactly). They filter the base used for percentage fee calculations.

Override a product’s cost #

add_filter( 'wpfcogs_get_product_cost', function ( $cost, $product_id, $parent_id, $args ) {
    if ( 1234 === (int) $product_id ) {
        $cost = 9.50;
    }
    return $cost;
}, 10, 4 );

Add a flat cost to every order’s profit calculation #

add_filter( 'wpfcogs_order_cost', function ( $total_cost, $order ) {
    return $total_cost + 1.20; // fixed pick-and-pack cost per order
}, 10, 2 );

Cost meta-key filters #

These let you tell the plugin which meta keys count as cost, or as extra profit, so a value another plugin stores is picked up.

Filter Filtered value Arguments
wpfcogs_cost_meta_keys The list of meta keys treated as cost $cost_meta_keys
wpfcogs_extra_profit_meta_keys The list of meta keys treated as extra profit $extra_profit_meta_keys
add_filter( 'wpfcogs_cost_meta_keys', function ( $keys ) {
    $keys[] = '_my_supplier_cost';
    return $keys;
} );

The settings gate filter #

wpfcogs_settings is how the plugin decides whether a Pro-only field is disabled. In the free version it returns the array array( 'disabled' => 'disabled' ), which disables the field. In Pro it returns '', removing the attribute. It is used across the settings screens and is not intended for store customization.

Validation gate filters #

A group of filters decides whether a whole feature registers at all. Each is seeded with true; return false to switch the feature off in code.

Filter Controls
wpfcogs_create_product_meta_box_validation The product cost meta box
wpfcogs_create_product_columns_validation The admin products list cost/profit columns
wpfcogs_create_orders_columns_validation The admin orders list cost/profit columns
wpfcogs_create_order_meta_box_validation The order edit cost/profit meta box
wpfcogs_create_wc_settings_tab_validation The Cost of Goods settings tab
wpfcogs_create_import_tool_validation The Import Costs tool
wpfcogs_create_edit_costs_tool_validation The Bulk Edit Costs tool
wpfcogs_create_report_validation The WooCommerce report
wpfcogs_create_analytics_orders_validation The Analytics orders integration
wpfcogs_update_order_items_costs_validation Whether order item costs are (re)calculated

Cost input validation filters #

These decide whether the cost and handling-fee inputs are shown on a given product. Return false to hide an input.

  • wpfcogs_add_cost_input_validation
  • wpfcogs_add_cost_input_variation_validation
  • wpfcogs_add_handling_fee_input_validation

User access filters #

Filter Passed value Arguments
wpfcogs_is_user_allowed true $allowed, $user, $allowed_user_roles
wpfcogs_is_user_allowed_roles configured roles $roles
add_filter( 'wpfcogs_is_user_allowed', function ( $allowed, $user, $roles ) {
    return user_can( $user, 'manage_woocommerce' ) ? $allowed : false;
}, 10, 3 );

Currency filters #

Used by the multicurrency cost calculation. If no rate is resolved, wpfcogs_currency_rate is passed 0.

  • wpfcogs_currency_rate – arguments $rate, $order, $currency
  • wpfcogs_currency_rate_option
  • wpfcogs_currencies_costs_total
  • wpfcogs_currencies_costs_percentage_total

Display and admin-email filters #

  • wpfcogs_cost_input_description, wpfcogs_cost_input_label_placeholders – the cost input’s description and label placeholders.
  • wpfcogs_order_metabox_value, wpfcogs_order_metabox_value_format_args, wpfcogs_order_metabox_cost_value_html – the order meta box output.
  • wpfcogs_order_admin_column_value, wpfcogs_order_admin_column_value_format_args – the orders list column output.
  • wpfcogs_order_admin_new_order_email_total_enabled, wpfcogs_order_admin_new_order_email_item_enabled, wpfcogs_admin_new_order_email_meta_enabled – whether each block is added to the admin new-order email.
  • wpfcogs_products_add_stock_cost_calculation_template, wpfcogs_products_add_stock_empty_cost_action – the Add stock average-cost expression and empty-cost behavior.

Actions #

Action Fires when
wpfcogs_core_loaded The plugin core has finished loading
wpfcogs_cost_input / wpfcogs_cost_input_variation After the product / variation cost input is rendered
wpfcogs_before_update_order_items_costs Before an order’s item costs are recalculated
wpfcogs_update_order_values_action When an order’s cost and profit values are updated
wpfcogs_run_import_tool When the Import Costs tool runs
wpfcogs_tools_after After the Tools sub-tab output
wpfcogs_save_settings / wpfcogs_on_update When settings are saved / the plugin updates

Shortcodes #

The plugin registers two shortcodes, both off by default. Enable them on the Shortcodes sub-tab first.

  • [wpfcogs_product_cost] – displays a product’s cost. Parameters: product_id, html_template.
  • [wpfcogs_product_profit] – displays a product’s profit. Parameters: product_id, profit_template, html_template.

The old tags [alg_wc_cog_product_cost] and [alg_wc_cog_product_profit] still resolve but emit a deprecation notice.

Deprecated hook migration table #

Every alg_wc_cog_* hook was renamed to wpfcogs_* in v4.1.6. The old names continue to work but emit _deprecated_hook() notices. The rename is a straight prefix swap; a representative set of the value and action hooks is shown below.

Old hook name Current hook name
alg_wc_cog_get_product_cost wpfcogs_get_product_cost
alg_wc_cog_order_cost wpfcogs_order_cost
alg_wc_cog_order_profit wpfcogs_order_profit
alg_wc_cog_order_item_cost wpfcogs_order_item_cost
alg_wc_cog_order_line_total wpfcogs_order_line_total
alg_wc_cog_cost_meta_keys wpfcogs_cost_meta_keys
alg_wc_cog_extra_profit_meta_keys wpfcogs_extra_profit_meta_keys
alg_wc_cog_is_user_allowed wpfcogs_is_user_allowed
alg_wc_cog_settings wpfcogs_settings
alg_wc_cog_core_loaded wpfcogs_core_loaded
alg_wc_cog_run_import_tool wpfcogs_run_import_tool

Need help? #

If you are extending Cost of Goods: Product Cost & Profit Calculator for WooCommerce and a hook does not behave as expected, contact WPFactory support with the filter name and a short code sample, and we will help you find the right extension point.