WordPress at a glance
function is not described

Automattic\WooCommerce\Admin\API\Reports\Coupons

DataStore::get_coupon_id() public WC 1.0

Get coupon ID for an order.

Tries to get the ID from order item meta, then falls back to a query of published coupons.

{} It's a method of the class: DataStore{}

No Hooks.

Return

Int. Coupon ID on success, 0 on failure.

Usage

$result = DataStore::get_coupon_id( \WC_Order_Item_Coupon $coupon_item );
\WC_Order_Item_Coupon $coupon_item (required)
-

Code of DataStore::get_coupon_id() WC 5.3.0

<?php
public static function get_coupon_id( \WC_Order_Item_Coupon $coupon_item ) {
	// First attempt to get coupon ID from order item data.
	$coupon_data = $coupon_item->get_meta( 'coupon_data', true );

	// Normal checkout orders should have this data.
	// See: https://github.com/woocommerce/woocommerce/blob/3dc7df7af9f7ca0c0aa34ede74493e856f276abe/includes/abstracts/abstract-wc-order.php#L1206.
	if ( isset( $coupon_data['id'] ) ) {
		return $coupon_data['id'];
	}

	// Try to get the coupon ID using the code.
	return wc_get_coupon_id_by_code( $coupon_item->get_code() );
}