@@ -29,9 +29,34 @@ class WC_Connect_Nux {
29
29
*/
30
30
private $ shipping_label ;
31
31
32
- function __construct ( WC_Connect_Tracks $ tracks , WC_Connect_Shipping_Label $ shipping_label ) {
33
- $ this ->tracks = $ tracks ;
34
- $ this ->shipping_label = $ shipping_label ;
32
+ /**
33
+ * @var WC_Connect_Service_Settings_Store
34
+ */
35
+ protected $ service_settings_store ;
36
+
37
+ /**
38
+ * @var WC_Connect_Payment_Methods_Store
39
+ */
40
+ protected $ payment_methods_store ;
41
+
42
+ /**
43
+ * @var WC_Connect_Service_Schemas_Store
44
+ */
45
+ protected $ service_schemas_store ;
46
+
47
+
48
+ function __construct (
49
+ WC_Connect_Tracks $ tracks ,
50
+ WC_Connect_Shipping_Label $ shipping_label ,
51
+ WC_Connect_Service_Settings_Store $ service_settings_store ,
52
+ WC_Connect_Payment_Methods_Store $ payment_methods_store ,
53
+ WC_Connect_Service_Schemas_Store $ service_schemas_store
54
+ ) {
55
+ $ this ->tracks = $ tracks ;
56
+ $ this ->shipping_label = $ shipping_label ;
57
+ $ this ->service_settings_store = $ service_settings_store ;
58
+ $ this ->payment_methods_store = $ payment_methods_store ;
59
+ $ this ->service_schemas_store = $ service_schemas_store ;
35
60
36
61
$ this ->init_pointers ();
37
62
}
@@ -436,6 +461,68 @@ public function set_up_nux_notices() {
436
461
add_action ( 'admin_notices ' , array ( $ this , 'show_tos_banner ' ) );
437
462
break ;
438
463
case 'after_cxn_us_no_wcs_plugin ' :
464
+ // Enqueue the migration modal assets specifically for this banner on the plugins page.
465
+ $ plugin_version = WC_Connect_Loader::get_wcs_version ();
466
+ // Use the public static method from WC_Connect_Loader
467
+ $ base_url = WC_Connect_Loader::get_wc_connect_base_url (); // Assuming get_wc_connect_base_url is static
468
+
469
+ wp_register_style ( 'wcst_wcshipping_migration_admin_notice ' , $ base_url . 'woocommerce-services-wcshipping-migration-admin-notice- ' . $ plugin_version . '.css ' , array (), null ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
470
+ // Add 'wp-element' and 'wc_connect_admin' dependency for React and base script
471
+ wp_register_script ( 'wcst_wcshipping_migration_admin_notice ' , $ base_url . 'woocommerce-services-wcshipping-migration-admin-notice- ' . $ plugin_version . '.js ' , array ( 'wc_connect_admin ' , 'wp-element ' ), null , true ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
472
+
473
+ // Localize script data - MATCHING the original register_wcshipping_migration_modal
474
+ // Note: The modal primarily uses data-args, localization is minimal here.
475
+ wp_localize_script (
476
+ 'wcst_wcshipping_migration_admin_notice ' ,
477
+ 'wcsPluginData ' , // Ensure this matches the expected object name in the script
478
+ array (
479
+ 'assetPath ' => $ base_url ,
480
+ 'adminPluginPath ' => admin_url ( 'plugins.php ' ),
481
+ )
482
+ );
483
+
484
+ // Enqueue scripts/styles needed for the banner and modal
485
+ wp_enqueue_script ( 'wc_connect_admin ' ); // Ensure base script is loaded first
486
+ wp_enqueue_script ( 'wcst_wcshipping_migration_admin_notice ' );
487
+ wp_enqueue_style ( 'wcst_wcshipping_migration_admin_notice ' );
488
+ wp_enqueue_style ( 'wc_connect_banner ' );
489
+
490
+ // Add the action to render the notice and container div
491
+ add_action (
492
+ 'admin_notices ' ,
493
+ function () use ( $ banner_to_display ) {
494
+ // Instantiate settings classes HERE, inside the closure, using stored dependencies
495
+ $ account_settings = new WC_Connect_Account_Settings (
496
+ $ this ->service_settings_store ,
497
+ $ this ->payment_methods_store
498
+ );
499
+ $ packages_settings = new WC_Connect_Package_Settings (
500
+ $ this ->service_settings_store ,
501
+ $ this ->service_schemas_store
502
+ );
503
+
504
+ // Prepare the data for the data-args attribute by calling get()
505
+ $ container_data_args = array (
506
+ 'nonce ' => wp_create_nonce ( 'wp_rest ' ),
507
+ 'baseURL ' => get_rest_url (),
508
+ 'accountSettings ' => $ account_settings ->get (), // Get REAL data
509
+ 'packagesSettings ' => $ packages_settings ->get (), // Get REAL data
510
+ );
511
+ $ encoded_container_args = wp_json_encode ( $ container_data_args );
512
+
513
+ // Echo the container div needed for the modal React component BEFORE the banner.
514
+ // Add 'display: none;' initially; the script should manage visibility.
515
+ printf (
516
+ '<div id="wcst_wcshipping_migration_admin_notice_feature_announcement" data-args="%s" style="display: none;"></div> ' ,
517
+ esc_attr ( $ encoded_container_args ) // Use the REAL encoded data
518
+ );
519
+
520
+ // Now show the banner itself
521
+ $ this ->show_contextual_after_connection_banner ( $ banner_to_display );
522
+ }
523
+ );
524
+ break ; // End case 'after_cxn_us_no_wcs_plugin'
525
+
439
526
case 'after_cxn_us_with_wcs_plugin ' :
440
527
case 'after_cxn_non_us ' :
441
528
wp_enqueue_style ( 'wc_connect_banner ' );
@@ -453,6 +540,10 @@ function () use ( $banner_to_display ) {
453
540
}
454
541
455
542
public function show_banner_before_connection () {
543
+ if ( get_option ( 'wcs_nux_any_banner_shown ' , false ) ) {
544
+ return ;
545
+ }
546
+
456
547
if ( ! $ this ->should_display_nux_notice_for_current_store_locale () ) {
457
548
return ;
458
549
}
@@ -486,10 +577,16 @@ public function show_banner_before_connection() {
486
577
'should_show_terms ' => true ,
487
578
);
488
579
580
+ update_option ( 'wcs_nux_any_banner_shown ' , true );
581
+
489
582
$ this ->show_nux_banner ( $ banner_content );
490
583
}
491
584
492
585
public function show_banner_after_connection () {
586
+ if ( get_option ( 'wcs_nux_any_banner_shown ' , false ) ) {
587
+ return ;
588
+ }
589
+
493
590
if ( ! $ this ->should_display_nux_notice_for_current_store_locale () ) {
494
591
return ;
495
592
}
@@ -504,6 +601,7 @@ public function show_banner_after_connection() {
504
601
WC_Connect_Options::delete_option ( self ::SHOULD_SHOW_AFTER_CXN_BANNER );
505
602
// Set the flag for the next contextual banner
506
603
WC_Connect_Options::update_option ( self ::SHOULD_SHOW_CONTEXTUAL_BANNER , true );
604
+ delete_option ( 'wcs_nux_any_banner_shown ' );
507
605
wp_safe_redirect ( remove_query_arg ( 'wcs-nux-notice ' ) );
508
606
exit ;
509
607
}
@@ -518,6 +616,8 @@ public function show_banner_after_connection() {
518
616
$ description_base = __ ( 'You can now enjoy %s. ' , 'woocommerce-services ' );
519
617
$ feature_list = $ this ->get_feature_list_for_country ( $ country );
520
618
619
+ update_option ( 'wcs_nux_any_banner_shown ' , true );
620
+
521
621
$ this ->show_nux_banner (
522
622
array (
523
623
'title ' => __ ( 'Setup complete. ' , 'woocommerce-services ' ),
@@ -538,6 +638,10 @@ public function show_banner_after_connection() {
538
638
}
539
639
540
640
public function show_contextual_after_connection_banner ( $ banner_type ) {
641
+ if ( get_option ( 'wcs_nux_any_banner_shown ' , false ) ) {
642
+ return ;
643
+ }
644
+
541
645
$ screen = get_current_screen ();
542
646
543
647
// This specific banner should only appear on the plugins page.
@@ -554,6 +658,7 @@ public function show_contextual_after_connection_banner( $banner_type ) {
554
658
if ( isset ( $ _GET ['wcs-nux-notice ' ] ) && 'dismiss ' === $ _GET ['wcs-nux-notice ' ] ) {
555
659
// Delete the flag for this contextual banner
556
660
WC_Connect_Options::delete_option ( self ::SHOULD_SHOW_CONTEXTUAL_BANNER );
661
+ delete_option ( 'wcs_nux_any_banner_shown ' );
557
662
wp_safe_redirect ( remove_query_arg ( 'wcs-nux-notice ' ) );
558
663
exit ;
559
664
}
@@ -564,17 +669,21 @@ public function show_contextual_after_connection_banner( $banner_type ) {
564
669
// Using a generic tracks event, can be made more specific if needed.
565
670
$ this ->tracks ->opted_in ( 'contextual_connection_banner_viewed ' );
566
671
672
+ update_option ( 'wcs_nux_any_banner_shown ' , true );
673
+
567
674
$ banner_title = '' ;
568
675
$ banner_description = '' ;
569
676
$ banner_button_text = '' ;
570
677
$ banner_button_link = null ;
571
678
679
+ update_option ( 'wcshipping_migration_state ' , '0 ' );
572
680
switch ( $ banner_type ) {
573
681
case 'after_cxn_us_no_wcs_plugin ' :
574
682
$ banner_title = __ ( 'WooCommerce Shipping & Tax has been renamed to WooCommerce Tax ' , 'woocommerce-services ' );
575
683
$ banner_description = __ ( 'Your tax functionality will continue to work as expected. The shipping functionality in this plugin will be discontinued on September 1, 2025. Please migrate to the new WooCommerce Shipping extension to get discounted labels for UPS, USPS, DHL Express— and more coming soon! ' , 'woocommerce-services ' );
576
684
$ banner_button_text = __ ( 'Try WooCommerce Shipping ' , 'woocommerce-services ' );
577
- $ banner_button_link = '' ;
685
+ // Ensure this line uses the special trigger value:
686
+ $ banner_button_link = '#trigger-migration-modal ' ;
578
687
break ;
579
688
case 'after_cxn_us_with_wcs_plugin ' :
580
689
$ banner_title = __ ( 'WooCommerce Shipping & Tax has been renamed to WooCommerce Tax ' , 'woocommerce-services ' );
@@ -613,6 +722,10 @@ public function show_contextual_after_connection_banner( $banner_type ) {
613
722
}
614
723
615
724
public function show_tos_banner () {
725
+ if ( get_option ( 'wcs_nux_any_banner_shown ' , false ) ) {
726
+ return ;
727
+ }
728
+
616
729
if ( ! $ this ->should_display_nux_notice_for_current_store_locale () ) {
617
730
return ;
618
731
}
@@ -628,6 +741,8 @@ public function show_tos_banner() {
628
741
629
742
$ this ->tracks ->opted_in ( 'tos_banner ' );
630
743
744
+ delete_option ( 'wcs_nux_any_banner_shown ' );
745
+
631
746
wp_safe_redirect ( remove_query_arg ( 'wcs-nux-tos ' ) );
632
747
exit ;
633
748
}
@@ -637,6 +752,8 @@ public function show_tos_banner() {
637
752
$ description_base = __ ( "WooCommerce Tax is almost ready to go! Once you connect your site to WordPress.com you'll have access to %s. " , 'woocommerce-services ' );
638
753
$ feature_list = $ this ->get_feature_list_for_country ( $ country );
639
754
755
+ update_option ( 'wcs_nux_any_banner_shown ' , true );
756
+
640
757
$ this ->show_nux_banner (
641
758
array (
642
759
'title ' => __ ( 'Connect your site to activate WooCommerce Tax ' , 'woocommerce-services ' ),
@@ -694,12 +811,23 @@ public function show_nux_banner( $content ) {
694
811
</p>
695
812
<?php endif ; ?>
696
813
<?php if ( isset ( $ content ['button_link ' ] ) ) : ?>
697
- <a
698
- class="wcs-nux__notice-content-button button button-primary"
699
- href="<?php echo esc_url ( $ content ['button_link ' ] ); ?> "
700
- >
701
- <?php echo esc_html ( $ content ['button_text ' ] ); ?>
702
- </a>
814
+ <?php // Check for the special modal trigger value ?>
815
+ <?php if ( '#trigger-migration-modal ' === $ content ['button_link ' ] ) : ?>
816
+ <button
817
+ type="button"
818
+ id="wcst-wcshipping-migration-notice__click" <?php // Ensure this ID matches what the JS expects ?>
819
+ class="wcs-nux__notice-content-button button button-primary"
820
+ >
821
+ <?php echo esc_html ( $ content ['button_text ' ] ); ?>
822
+ </button>
823
+ <?php else : ?>
824
+ <a
825
+ class="wcs-nux__notice-content-button button button-primary"
826
+ href="<?php echo esc_url ( $ content ['button_link ' ] ); ?> "
827
+ >
828
+ <?php echo esc_html ( $ content ['button_text ' ] ); ?>
829
+ </a>
830
+ <?php endif ; ?>
703
831
<?php else : ?>
704
832
<form action="<?php echo esc_attr ( admin_url ( 'admin-post.php ' ) ); ?> " method="post">
705
833
<input type="hidden" name="action" value="register_woocommerce_services_jetpack"/>
0 commit comments