ByteKeel Order Profit: Hooks and filters
The filters and action in ByteKeel Order Profit (unchanged since 1.1.2), with arguments, the stored data and an example that reads another meta field.
Filters
wc_profit_calculator_product_cost
Filters the unit cost of a product or variation, wherever the plugin needs it: order calculation, the product list and the Profit tab.
$cost(float|null): the product’s_wc_cost_of_goods, or for a variation without its own cost the parent’s.nullwhen no cost is set.$product(WC_Product): the product or variation.
Return null for “no cost”, which is counted as zero and flagged as missing.
wc_profit_calculator_order_profit
Filters an order’s calculated profit data before it is shown or saved. Arguments: $data (array) and $order (WC_Order). The array holds revenue, product_costs, gateway_fee, packaging_cost, total_cost, profit, margin, missing_costs, items, calculated_at and version. If you change amounts, keep profit and margin consistent with them.
Actions
wc_profit_calculator_loaded
Fires once the plugin has started (only when WooCommerce is active). No arguments.
Example: read costs from another plugin’s field
This snippet uses a cost stored by another plugin under _purchase_price when a product has no cost of its own. Put it in a small custom plugin or your child theme’s functions.php, then run Recalculate all orders.
add_filter( 'wc_profit_calculator_product_cost', function ( $cost, $product ) {
if ( null !== $cost ) {
return $cost; // The plugin's own cost wins.
}
$other = $product->get_meta( '_purchase_price', true ); // Your own meta key.
return '' === $other ? null : (float) $other;
}, 10, 2 );
Stored data
- Product and variation meta
_wc_cost_of_goods: unit cost. - Order meta
_wc_profit_data(array) plus_wc_profit_amount,_wc_profit_cost,_wc_profit_revenueand_wc_profit_margin, written with the WooCommerce order API, so HPOS on or off. - Table
{prefix}wc_product_cost_history: product_id, variation_id, old_cost, new_cost, changed_by, changed_date, note. - Option
wc_profit_calculator_settings.
Deleting the plugin always removes its options; with Delete data ticked in Settings it also removes the meta above and the cost history.
Did this answer the question? No — open a support request