Skip to content

Commit

Permalink
Display migration banner on all WC settings page [shipping-152] (#2771)
Browse files Browse the repository at this point in the history
* Show upgrade banner on shipping settings page as well

* Make sure clicking the confirm upgrade button doesn't refresh the page

* Show update banner on all settings pages
  • Loading branch information
samnajian authored and Ferdev committed Jul 30, 2024
1 parent 2eb262b commit 1c6473e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion client/wcshipping-migration-admin-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ const wcstMigrationNoticeDimissButton = document.querySelector('.wcst-wcshipping
// Add all button events
["click", "keydown"].forEach(eventName => {
// Clicking "Confirm update" will start the migration. This is the same as popping up the modal and clicking the "Update" button there.
wcstWCShippingMigrationNoticeButton.addEventListener(eventName, () => {
wcstWCShippingMigrationNoticeButton.addEventListener(eventName, (evt) => {
/**
* Prevent form submission when rendered in a form or alike that listens to button click
*/
evt.preventDefault();
// Pop open feature announcement modal.
ReactDOM.render(
<Provider store={store}>
Expand Down
15 changes: 10 additions & 5 deletions woocommerce-services.php
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ public function init_shipping() {
add_action( 'admin_print_footer_scripts', array( $this, 'add_sift_js_tracker' ) );
add_filter( 'woocommerce_hidden_order_itemmeta', array( $this, 'hide_wc_connect_package_meta_data' ) );
add_filter( 'is_protected_meta', array( $this, 'hide_wc_connect_order_meta_data' ), 10, 3 );
add_action( 'current_screen', array( $this, 'edit_orders_page_actions' ) );
add_action( 'current_screen', array( $this, 'maybe_render_upgrade_banner' ) );
}

/**
Expand Down Expand Up @@ -1518,7 +1518,7 @@ private function get_i18n_json() {
*
* @return boolean
*/
public function is_on_order_list_page() {
public function should_render_upgrade_banner() {
if ( ! is_admin() ) {
return false;
}
Expand All @@ -1542,6 +1542,11 @@ public function is_on_order_list_page() {
return false;
}

// All WC settings pages
if ( $screen->id === 'woocommerce_page_wc-settings' ) {
return true;
}

/*
* Non-HPOS:
* $screen->id = "edit-shop_order"
Expand All @@ -1558,8 +1563,8 @@ public function is_on_order_list_page() {
return true;
}

public function edit_orders_page_actions() {
if ( ! $this->is_on_order_list_page() ) {
public function maybe_render_upgrade_banner() {
if ( ! $this->should_render_upgrade_banner() ) {
// If this is not on the order list page, then don't add any action.
return;
}
Expand Down Expand Up @@ -1993,7 +1998,7 @@ public function display_wcst_to_wcshipping_migration_notice() {
'</p>
<button type="button" class="notice-dismiss %s"><span class="screen-reader-text">Dismiss this notice.</span></button>
</div>
<div class="notice-action"><button id="wcst-wcshipping-migration-notice__click" class="action-button">%s</button></div>
<div class="notice-action"><button id="wcst-wcshipping-migration-notice__click" type="button" class="action-button">%s</button></div>
</div>',
$banner->dismissible ? '' : 'hide-dismissible',
$banner->action
Expand Down

0 comments on commit 1c6473e

Please sign in to comment.