WC_Coupon::get_used_bypublicWC 3.0.0

Get records of all users who have used the current coupon.

The list is loaded lazily on first access rather than during object construction, because a coupon with hundreds of thousands of usages would otherwise allocate an enormous PHP array on every WC_Coupon instantiation — even for code paths such as order-status changes or cart validation that never need this data.

Method of the class: WC_Coupon{}

No Hooks.

Returns

Array.

Usage

$WC_Coupon = new WC_Coupon();
$WC_Coupon->get_used_by( $context );
$context(string)
What the value is for. Valid values are 'view' and 'edit'.
Default: 'view'

Changelog

Since 3.0.0 Introduced.

WC_Coupon::get_used_by() code WC 10.8.1

public function get_used_by( $context = 'view' ) {
	if ( is_null( $this->data['used_by'] ) ) {
		// Bypass set_prop() so the lazy fetch does not mark the object as dirty.
		$this->data['used_by'] = $this->get_id()
			? array_filter( (array) get_post_meta( $this->get_id(), '_used_by', false ) )
			: array();
	}
	return $this->get_prop( 'used_by', $context );
}