WC_Order_Item::calculate_cogs_value()
Calculate the Cost of Goods Sold value and set it as the actual value for this line item.
Method of the class: WC_Order_Item{}
Hooks from the method
Returns
true|false
. True if the value has been calculated successfully (and set as the actual value), false otherwise (and the value hasn't changed).
Usage
$WC_Order_Item = new WC_Order_Item(); $WC_Order_Item->calculate_cogs_value(): bool;
Changelog
Since 9.5.0 | Introduced. |
WC_Order_Item::calculate_cogs_value() WC Order Item::calculate cogs value code WC 9.8.5
public function calculate_cogs_value(): bool { if ( ! $this->has_cogs() || ! $this->cogs_is_enabled( __METHOD__ ) ) { return false; } $value = $this->calculate_cogs_value_core(); /** * Filter to modify the Cost of Goods Sold value that gets calculated for a given order item. * * @since 9.5.0 * * @param float|null $value The value originally calculated, null if it was not possible to calculate it. * @param WC_Order_Item $line_item The order item for which the value is calculated. */ $value = apply_filters( 'woocommerce_calculated_order_item_cogs_value', $value, $this ); if ( is_null( $value ) ) { return false; } $this->set_cogs_value( (float) $value ); return true; }