WC_Order_Item::get_cogs_value_per_unit_tooltip_text
Get the "cost per unit" tooltip text for the "Cost" (of Goods Sold) column in the order details page.
Method of the class: WC_Order_Item{}
Hooks from the method
Returns
String. "Cost per unit: (formatted cost with currency)" text.
Usage
$WC_Order_Item = new WC_Order_Item(); $WC_Order_Item->get_cogs_value_per_unit_tooltip_text(): string;
WC_Order_Item::get_cogs_value_per_unit_tooltip_text() WC Order Item::get cogs value per unit tooltip text code WC 10.7.0
public function get_cogs_value_per_unit_tooltip_text(): string {
if ( ! $this->cogs_is_enabled( __METHOD__ ) || ! $this->has_cogs() ) {
return '';
}
$tooltip_text = '';
$quantity = $this->get_quantity();
$cogs_value = $this->get_cogs_value();
$cost_per_item = 0;
$formatted_cost_per_item = '';
if ( $quantity > 0 && $cogs_value > 0 ) {
$cost_per_item = $cogs_value / $quantity;
$formatted_cost_per_item = wc_price(
$cost_per_item,
array(
'currency' => $this->get_order()->get_currency(),
'in_span' => false,
)
);
/* translators: %s = formatted cost with currency symbol. */
$tooltip_text = sprintf( __( 'Cost per unit: %s', 'woocommerce' ), $formatted_cost_per_item );
}
/**
* Filter to customize the text of the "Cost per unit" tooltip for the "Cost" (of Goods Sold) column in the order details page.
* If an empty string is returned then the tooltip won't be rendered.
*
* @param string $tooltip_text Original tooltip text, may be an empty string.
* @param float $cost_per_item The numerical value of the unit Cost of Goods Sold of the product.
* @param string $formatted_cost_per_item The unit Cost of Goods Sold of the product already formatted for display.
* @param WC_Order_Item $order_item The order item this filter is being fired for.
*
* @since 9.9.0
*/
return apply_filters( 'woocommerce_order_item_cogs_per_item_tooltip', $tooltip_text, $cost_per_item, $formatted_cost_per_item, $this );
}