DataStore::get_coupon_id()public staticWC 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.

Метод класса: DataStore{}

Хуков нет.


int. Coupon ID on success, 0 on failure.


$result = DataStore::get_coupon_id( $coupon_item );
$coupon_item(\WC_Order_Item_Coupon) (обязательный)
The coupon order item object.

Код DataStore::get_coupon_id() WC 8.6.1

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:
	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() );