Automattic\WooCommerce\Internal\Admin\Suggestions
PaymentExtensionSuggestions::get_extension_incentive()
Get the incentive details for a given extension and country, if any.
Method of the class: PaymentExtensionSuggestions{}
No Hooks.
Return
Array|null
. The incentive details for the given extension and country. Null if not found.
Usage
// private - for code of main (parent) class only $result = $this->get_extension_incentive( $extension_id, $country_code, $context ): ?array;
- $extension_id(string) (required)
- The extension ID.
- $country_code(string) (required)
- The two-letter country code.
- $context(string)
- The context ID of where the extension incentive is being used.
Default: ''
PaymentExtensionSuggestions::get_extension_incentive() PaymentExtensionSuggestions::get extension incentive code WC 9.6.0
private function get_extension_incentive( string $extension_id, string $country_code, string $context = '' ): ?array { // Try to map the context to an incentive type. $incentive_type = ''; if ( isset( $this->context_to_incentive_type_map[ $context ] ) ) { $incentive_type = $this->context_to_incentive_type_map[ $context ]; } $incentives = $this->suggestion_incentives->get_incentives( $extension_id, $country_code, $incentive_type ); if ( empty( $incentives ) ) { return null; } // Use the first incentive, in case there are multiple. $incentive = reset( $incentives ); // Sanitize the incentive details. $incentive = $this->sanitize_extension_incentive( $incentive ); // Enhance the incentive details. $incentive['_suggestion_id'] = $extension_id; // Add the dismissals list. $incentive['_dismissals'] = array_unique( array_values( $this->suggestion_incentives->get_incentive_dismissals( $incentive['id'], $extension_id ) ) ); return $incentive; }