Automattic\WooCommerce\Internal\Admin\Suggestions\Incentives
Incentive::is_visible
Check if an incentive should be visible.
Method of the class: Incentive{}
No Hooks.
Returns
true|false. Whether the incentive should be visible.
Usage
$Incentive = new Incentive(); $Incentive->is_visible( $id, $country_code, $skip_extension_active_check ): bool;
- $id(string) (required)
- The incentive ID to check for visibility.
- $country_code(string) (required)
- The business location country code to get incentives for.
- $skip_extension_active_check(true|false)
- Whether to skip the check for the extension plugin being active.
Default: false
Incentive::is_visible() Incentive::is visible code WC 10.3.5
public function is_visible( string $id, string $country_code, bool $skip_extension_active_check = false ): bool {
// The extension plugin must not be active, unless we are asked to skip the check.
if ( ! $skip_extension_active_check && $this->is_extension_active() ) {
return false;
}
// The current WP user must have the required capabilities.
if ( ! $this->user_has_caps() ) {
return false;
}
// An incentive must be available.
if ( empty( $this->get_by_id( $id, $country_code ) ) ) {
return false;
}
// If the incentive has been dismissed in all contexts, don't show it.
// We don't know the full list of contexts, so we can't assume anything beyond `all`.
if ( $this->is_dismissed( $id, 'all' ) ) {
return false;
}
return true;
}