Skip to content

Instantly share code, notes, and snippets.

@ankitrox
Created April 5, 2021 08:27
Show Gist options
  • Save ankitrox/1768ca893dbd67bd792e11cac2d70e9b to your computer and use it in GitHub Desktop.
Save ankitrox/1768ca893dbd67bd792e11cac2d70e9b to your computer and use it in GitHub Desktop.
Helper
<?php
public function prevent_duplicate_error_notices( string $message ): ?string {
if ( wc_has_notice( $message ) ) {
return null;
}
return $message;
}
public function wc_add_wp_error_notices( \WP_Error $errors ): void {
add_filter( 'woocommerce_add_error', [ $this, 'prevent_duplicate_error_notices' ] );
wc_add_wp_error_notices( $errors );
remove_filter( 'woocommerce_add_error', [ $this, 'prevent_duplicate_error_notices' ] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment