Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives

Incentive::get_by_promo_id()publicWC 1.0

Get an incentive by promo ID.

The incentives are filtered based on the country code, incentive type, if provided, and their visibility.

Method of the class: Incentive{}

No Hooks.

Return

?Array. The incentive details. Returns null if there is no incentive available.

Usage

$Incentive = new Incentive();
$Incentive->get_by_promo_id( $promo_id, $country_code, $incentive_type ): ?array;
$promo_id(string) (required)
The incentive promo ID.
$country_code(string) (required)
The business location country code to get incentives for.
$incentive_type(string)
The type of incentive to search for.
Default: ''

Incentive::get_by_promo_id() code WC 9.6.1

public function get_by_promo_id( string $promo_id, string $country_code, string $incentive_type = '' ): ?array {
	$incentives = array_filter(
		$this->get_all( $country_code, $incentive_type ),
		function ( $incentive ) use ( $promo_id ) {
			return $incentive['promo_id'] === $promo_id;
		}
	);

	if ( empty( $incentives ) ) {
		return null;
	}

	// Get the first found incentive, in the unlikely case there are multiple incentives with the same promo ID.
	return reset( $incentives );
}