Abstract_WC_Order_Item_Type_Data_Store::save_cogs_data
Persist the Cost of Goods Sold related data to the database.
Method of the class: Abstract_WC_Order_Item_Type_Data_Store{}
Hooks from the method
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->save_cogs_data( $item );
- $item(WC_Order_Item) (required)
- The order item for which the data will be persisted.
Abstract_WC_Order_Item_Type_Data_Store::save_cogs_data() Abstract WC Order Item Type Data Store::save cogs data code WC 10.4.3
private function save_cogs_data( WC_Order_Item $item ) {
$cogs_value = $item->get_cogs_value();
/**
* Filter to customize the Cost of Goods Sold value that gets saved for a given order item,
* or to suppress the saving of the value (so that custom storage can be used).
*
* @since 9.5.0
*
* @param float|null $cogs_value The value to be written to the database. If returned as null, nothing will be written.
* @param WC_Order_Item $item The order item for which the value is being saved.
*/
$cogs_value = apply_filters( 'woocommerce_save_order_item_cogs_value', $cogs_value, $item );
if ( is_null( $cogs_value ) ) {
return;
}
$cogs_value = (float) $cogs_value;
if ( 0.0 === $cogs_value ) {
$this->order_item_data_store->delete_metadata( $item->get_id(), '_cogs_value', '' );
} else {
$this->order_item_data_store->update_metadata( $item->get_id(), '_cogs_value', $cogs_value );
}
}