New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use WC built-in Action Scheduler to fetch in-app promotions #45628
Conversation
Hi @Dan-Q, @andfinally, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
Test Results SummaryCommit SHA: 73f1371
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
3e6b651
to
28b9af4
Compare
…Admin` constructor. `WC_Admin` is only instantiated in an admin request. If we init marketplace promotions from `woocommerce_init`, we'll be too late to add the callback for the scheduled action that fetches promotion data.
28b9af4
to
ac3380f
Compare
… time it runs. This allows more frequent changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything works as expected. Action is triggered when needed, the specified endpoint is called and both bubble and notice are visible.
plugins/woocommerce/includes/admin/class-wc-admin-marketplace-promotions.php
Show resolved
Hide resolved
… from the `WC_Admin` constructor. But `WC_Admin` is only instantiated during `is_admin` requests. We also need to respond to cron requests. So we're now including the class from `class-woocommerce.php` if the context is admin or cron, and instantiating it on `init`. This fixes the error in Scheduled Action `action failed via WP Cron: Scheduled action for woocommerce_marketplace_fetch_promotions will not be executed as no callbacks are registered.`
Thanks for the review Michal! 🙌 I've committed a small change to ensure the scheduled action works when run by cron.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍 Tested on a new JN site and things worked as expected. Also tested that a woocommerce_marketplace_suppress_promotions
filter cancels the scheduled action.
Submission Review Guidelines:
Changes proposed in this Pull Request:
In #44655 and related PRs, we introduced logic to fetch data from a new Woo.com endpoint and show notices on the WooCommerce Marketplace pages, as well as a bubble on the
WooCommerce > Extensions
menu item. That logic, based on events scheduled withwp_schedule_event
, didn't run on JN and other external sites, so the notices weren't shown. In this PR, we are using ActionScheduler to schedule the event withas_schedule_recurring_action
.Closes 19763-gh-Automattic/woocommerce.com.
How to test the changes in this Pull Request:
If you're using a local
wp-env
environmentplugins/woocommerce/includes/admin/class-wc-admin-marketplace-promotions.php
and replace thePROMOTIONS_API_URL
valuehttps://woo.com/wp-json/wccom-extensions/3.0/promotions
withhttps://gist.githubusercontent.com/andfinally/acd8646151c0108f92979c985c20a0d8/raw/
. This is a gist with dummy data that is valid until 31 March.nvm use
.cd plugins/woocommerce
.pnpm -- wp-env start
to start wp-env.pnpm --filter='@woocommerce/plugin-woocommerce' build
.woocommerce_marketplace_fetch_promotions
. Note that the action is pending.WooCommerce > Extensions
menu item, and the notice should appear on the default Marketplace pagehttp://localhost:8888/wp-admin/admin.php?page=wc-admin&path=%2Fextensions
. (It also appears on the Themes and other tabs on that page – that's intentional.)class-wc-admin-marketplace-promotions.php
again and change thePROMOTIONS_API_URL
tohttps://gist.githubusercontent.com/andfinally/8ffca3fe3844fee6e146a80e563f00bb/raw/
. This is a second gist, where the expiry dates for the promotions have passed.If you're using a JN or other external site
plugins/woocommerce/bin/build-zip.sh
. This skips a memory-intensive process in the WooCommerce zip build that is irrelevant to this change.pnpm --filter='@woocommerce/plugin-woocommerce' build:zip
.woocommerce.zip
plugin file inplugins/woocommerce
. Install the plugin in your external site.WooCommerce > Extensions
menu item, and the notice should appear on thewp-admin/admin.php?page=wc-admin&path=%2Fextensions
page.PROMOTIONS_API_URL
tohttps://gist.githubusercontent.com/andfinally/8ffca3fe3844fee6e146a80e563f00bb/raw/
. This is a second gist, where the expiry dates for the promotions have passed. If you have SSH access to your site, you can make this change directly in the PHP file.Changelog entry
Significance
Type
Message
Comment