WC_Order_Data_Store_CPT::handle_cogs_value_update
Handle the update of COGS value during post meta update. This method processes COGS-specific logic and determines if the standard update flow should be skipped.
Method of the class: WC_Order_Data_Store_CPT{}
Hooks from the method
Returns
true|false. True if the standard update flow should be skipped, false otherwise.
Usage
// private - for code of main (parent) class only $result = $this->handle_cogs_value_update( $order, $value, $order_id, $meta_key, $updated_props, $prop );
- $order(WC_Order) (required)
- The order being updated.
- $value(required) (passed by reference — &)
- .
- $order_id(int) (required)
- The order ID.
- $meta_key(string) (required)
- The meta key being updated.
- $updated_props(required) (passed by reference — &)
- .
- $prop(string) (required)
- The property name.
WC_Order_Data_Store_CPT::handle_cogs_value_update() WC Order Data Store CPT::handle cogs value update code WC 10.5.0
private function handle_cogs_value_update( $order, &$value, $order_id, $meta_key, &$updated_props, $prop ) {
if ( ! $this->cogs_is_enabled() || ! $order->has_cogs() ) {
return true;
}
/**
* Filter to customize the Cost of Goods Sold value that gets saved for a given order,
* 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_Abstract_Order $item The order for which the value is being saved.
*/
$value = apply_filters( 'woocommerce_save_order_cogs_value', $value, $order );
if ( is_null( $value ) ) {
return true;
}
// Delete meta if value is zero (optimization).
if ( 0.0 === (float) $value ) {
delete_post_meta( $order_id, $meta_key );
$updated_props[] = $prop;
return true;
}
// Let the standard flow handle the update (with the filtered value).
return false;
}