Custom Product Costs For WooCommerce
What Does This Feature Do?
This feature allows you to assign custom product costs to each product in WooCommerce in addition to the Product Cost Of Goods (which is a mandatory field for Alpha Insights).
These additional costs are used in your total profit calculations as part of Alpha Insights.
How Does This Feature Work?
You can set up as many custom product costs as you’d like using a simple filter which we will demonstrate below.
Once setup, you can assign a default cost for each product, as well as overriding at the order level, more detail further below.
Setting Up Your Custom Product Costs
1. Add the snippet below to functions.php
Not sure how to add to functions.php? Check out our guide here.
Update the snippet below to suit, the array key (e.g. shipping_costs) is used as the unique identifier for each custom cost.Â
If you ever update the array key, it will reference a new custom cost.
/**
*
* Add custom product cost inputs to the product page
*
* @param array The Custom product costs
* @param int The product ID to check against
*
**/
add_filter( 'wpd_ai_custom_product_costs', 'wpd_additional_product_cost_inputs', 10, 2 );
function wpd_additional_product_cost_inputs( $custom_product_costs, $product_id ) {
// Shipping
$custom_product_costs['shipping_costs'] = array(
'label' => 'Shipping Costs',
'description' => 'Shipping costs for each unit of this product sold.',
'placeholder' => ''
);
// Packaging
$custom_product_costs['packaging_costs'] = array(
'label' => 'Packaging Costs',
'description' => 'Packaging costs for each unit of this product sold.',
'placeholder' => ''
);
// Packaging
$custom_product_costs['transaction_fees'] = array(
'label' => 'Transaction Fees',
'description' => 'Additional fees associated with this product.',
'placeholder' => ''
);
// Return results
return $custom_product_costs;
}
2. Setup Default Product Costs
You can setup default product costs for each of your products as outlined in the image below from the single product page.
These will be the default values used for the order, however you can override these values per order if you would like.
Overriding Product Costs At The Order Level
Update Custom Product Costs At Line Item Level
If you have enabled the custom product costs correctly, you will see a few new fields on your WooCommerce order page.
Each line item will now have a new input field for each of the custom product costs that you setup.
By default it will use the value you have set at the product level, or 0 if not set.
You can override these for each order by entering a number into the input and clicking Save & Recalculate or by updating the order.
You should see the updated value reflected in the input, in the line item summary (Alpha Insights COGS) and it should also update the total costs in the Alpha Insights Summary Dashboard.
Update Custom Product Costs Total For An Order
If you have any custom product costs enabled, there will also be a new input field in the Alpha Insights Summary Dashboard called “Total Product Custom Costs”.
By default, this is the sum of all the line item costs.
You can override this value if you would like, but this will totally ignore all line item inputs & assign the total custom product costs as the value you have set here.