WC_Order_Item::calculate_cogs_value
Calculate the Cost of Goods Sold value and set it as the actual value for this line item.
Метод класса: WC_Order_Item{}
Хуки из метода
Возвращает
true|false. True if the value has been calculated successfully (and set as the actual value), false otherwise (and the value hasn't changed).
Использование
$WC_Order_Item = new WC_Order_Item(); $WC_Order_Item->calculate_cogs_value(): bool;
Список изменений
| С версии 9.5.0 | Введена. |
Код WC_Order_Item::calculate_cogs_value() WC Order Item::calculate cogs value WC 10.8.1
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;
}