Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives
Incentive::get_by_id()
Get an incentive by 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_id( $incentive_id, $country_code ): ?array;
- $incentive_id(string) (required)
- The incentive ID.
- $country_code(string) (required)
- The business location country code to get incentives for.
Incentive::get_by_id() Incentive::get by id code WC 9.6.0
public function get_by_id( string $incentive_id, string $country_code ): ?array { $incentives = array_filter( $this->get_all( $country_code ), function ( $incentive ) use ( $incentive_id ) { return $incentive['id'] === $incentive_id; } ); if ( empty( $incentives ) ) { return null; } // Get the first found incentive, in the unlikely case there are multiple incentives with the same ID. return reset( $incentives ); }