Automattic / Automattic/woocommerce-services
Use `WC()->is_wc_admin_active()` to check for WC Admin note support
- Dominant language
- JavaScript
- Stars
- 112
- Forks
- 31
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 14
Description
When trying to display the "DHL Express live rates are now available" note, [WCS&T currently checks](https://github.com/Automattic/woocommerce-services/pull/2402) if the following will throw an exception:
```php
try {
WC_Data_Store::load( 'admin-note' );
} catch ( Exception $e ) {
return false;
}
```
(For some context, the problem originally stems from the fact that WC Admin can be available as a plugin but can have its functionality disabled using a filter, in which case the `admin-note` data store does not exist).
While this currently does the job, @adrianduffell suggested [in this issue](https://github.com/woocommerce/woocommerce-admin/issues/6703) that `WC()->is_wc_admin_active()` can be used to check if we can add a note. The approach should be changed to be in line with this best practice.
**UPDATE:** `NoteTraits` now throws an exception if the store isn't available that can be caught instead of checking this but both solutions would work.
Contributor guide
Research direction
Start from the current WCS&T check that calls WC_Data_Store::load('admin-note') and review the linked pull request for its location. Compare that approach with WC()->is_wc_admin_active() and the NoteTraits exception behavior. Done means the note-support check follows the recommended WooCommerce Admin approach without breaking note display.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100