Automattic\WooCommerce\Internal\Admin\Settings
PaymentsProviders::hide_extension_suggestion
Hide a payment extension suggestion.
Method of the class: PaymentsProviders{}
No Hooks.
Returns
true|false. True if the suggestion was successfully hidden, false otherwise.
Usage
$PaymentsProviders = new PaymentsProviders(); $PaymentsProviders->hide_extension_suggestion( $id ): bool;
- $id(string) (required)
- The ID of the payment extension suggestion to hide.
PaymentsProviders::hide_extension_suggestion() PaymentsProviders::hide extension suggestion code WC 10.7.0
public function hide_extension_suggestion( string $id ): bool {
// We may receive a suggestion ID that is actually an order map ID used in the settings page providers list.
// Extract the suggestion ID from the order map ID.
if ( $this->is_suggestion_order_map_id( $id ) ) {
$id = $this->get_suggestion_id_from_order_map_id( $id );
}
$suggestion = $this->get_extension_suggestion_by_id( $id );
if ( is_null( $suggestion ) ) {
throw new Exception( esc_html__( 'Invalid suggestion ID.', 'woocommerce' ) );
}
$user_payments_nox_profile = get_user_meta( get_current_user_id(), Payments::PAYMENTS_NOX_PROFILE_KEY, true );
if ( empty( $user_payments_nox_profile ) ) {
$user_payments_nox_profile = array();
} else {
$user_payments_nox_profile = maybe_unserialize( $user_payments_nox_profile );
}
// Mark the suggestion as hidden.
if ( empty( $user_payments_nox_profile['hidden_suggestions'] ) ) {
$user_payments_nox_profile['hidden_suggestions'] = array();
}
// Check if it is already hidden.
if ( in_array( $id, array_column( $user_payments_nox_profile['hidden_suggestions'], 'id' ), true ) ) {
return true;
}
$user_payments_nox_profile['hidden_suggestions'][] = array(
'id' => $id,
'timestamp' => time(),
);
$result = update_user_meta( get_current_user_id(), Payments::PAYMENTS_NOX_PROFILE_KEY, $user_payments_nox_profile );
// Since we already check if the suggestion is already hidden, we should not get a false result
// for trying to update with the same value. False means the update failed and the suggestion is not hidden.
if ( false === $result ) {
return false;
}
return true;
}