diff --git a/plugins/woocommerce-admin/src/API/OnboardingPlugins.php b/plugins/woocommerce-admin/src/API/OnboardingPlugins.php index af0d28fecac..bf49219307f 100644 --- a/plugins/woocommerce-admin/src/API/OnboardingPlugins.php +++ b/plugins/woocommerce-admin/src/API/OnboardingPlugins.php @@ -122,8 +122,9 @@ class OnboardingPlugins extends \WC_REST_Data_Controller { return apply_filters( 'woocommerce_onboarding_plugins_whitelist', array( - 'jetpack' => 'jetpack/jetpack.php', - 'woocommerce-services' => 'woocommerce-services/woocommerce-services.php', + 'facebook-for-woocommerce' => 'facebook-for-woocommerce/facebook-for-woocommerce.php', + 'jetpack' => 'jetpack/jetpack.php', + 'woocommerce-services' => 'woocommerce-services/woocommerce-services.php', ) ); } diff --git a/plugins/woocommerce-admin/src/Events.php b/plugins/woocommerce-admin/src/Events.php index 2114cea02b6..9dd40352df2 100644 --- a/plugins/woocommerce-admin/src/Events.php +++ b/plugins/woocommerce-admin/src/Events.php @@ -10,6 +10,7 @@ namespace Automattic\WooCommerce\Admin; defined( 'ABSPATH' ) || exit; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Facebook_Extension; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Giving_Feedback_Notes; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Mobile_App; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_New_Sales_Record; @@ -60,5 +61,6 @@ class Events { WC_Admin_Notes_New_Sales_Record::possibly_add_sales_record_note(); WC_Admin_Notes_Giving_Feedback_Notes::add_notes_for_admin_giving_feedback(); WC_Admin_Notes_Mobile_App::possibly_add_mobile_app_note(); + WC_Admin_Notes_Facebook_Extension::possibly_add_facebook_note(); } } diff --git a/plugins/woocommerce-admin/src/FeaturePlugin.php b/plugins/woocommerce-admin/src/FeaturePlugin.php index 040486d20a6..c34350f6d9c 100644 --- a/plugins/woocommerce-admin/src/FeaturePlugin.php +++ b/plugins/woocommerce-admin/src/FeaturePlugin.php @@ -10,6 +10,7 @@ namespace Automattic\WooCommerce\Admin; defined( 'ABSPATH' ) || exit; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Facebook_Extension; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Historical_Data; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Order_Milestones; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Welcome_Message; @@ -151,6 +152,7 @@ class FeaturePlugin { new WC_Admin_Notes_Historical_Data(); new WC_Admin_Notes_Order_Milestones(); new WC_Admin_Notes_Welcome_Message(); + new WC_Admin_Notes_Facebook_Extension(); } /** diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Extension.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Extension.php new file mode 100644 index 00000000000..839cbcc816a --- /dev/null +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Extension.php @@ -0,0 +1,103 @@ +publish < 1 ) { + return; + } + + $current_time = time(); + $three_days_in_seconds = 3 * DAY_IN_SECONDS; + + // We want to show the Facebook note after day 3. + if ( $current_time - $wc_admin_installed < $three_days_in_seconds ) { + return; + } + + $data_store = \WC_Data_Store::load( 'admin-note' ); + + // We already have this note? Then exit, we're done. + $note_ids = $data_store->get_notes_with_name( self::NOTE_NAME ); + if ( ! empty( $note_ids ) ) { + return; + } + + include_once ABSPATH . '/wp-admin/includes/plugin.php'; + + $content = __( 'Grow your business by targeting the right people and driving sales with Facebook. You can install this free extension now.', 'woocommerce-admin' ); + + $note = new WC_Admin_Note(); + $note->set_title( __( 'Market on Facebook', 'woocommerce-admin' ) ); + $note->set_content( $content ); + $note->set_content_data( (object) array() ); + $note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL ); + $note->set_icon( 'thumbs-up' ); + $note->set_name( self::NOTE_NAME ); + $note->set_source( 'woocommerce-admin' ); + $note->add_action( 'learn-more', __( 'Learn more', 'woocommerce-admin' ), 'https://woocommerce.com/products/facebook/', WC_Admin_Note::E_WC_ADMIN_NOTE_UNACTIONED ); + $note->add_action( 'install-now', __( 'Install now', 'woocommerce-admin' ), false, WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED, true ); + + // Create the note as "actioned" if the Facebook extension is already installed. + if ( 0 === validate_plugin( 'facebook-for-woocommerce/facebook-for-woocommerce.php' ) ) { + $note->set_status( WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED ); + } + + $note->save(); + } + + /** + * Install Facebook extension when note is actioned. + */ + public function install_facebook_extension( $note ) { + if ( self::NOTE_NAME === $note->get_name() ) { + $plugin = array( 'plugin' => 'facebook-for-woocommerce' ); + $installer = new \Automattic\WooCommerce\Admin\API\OnboardingPlugins(); + $result = $installer->install_plugin( $plugin ); + + if ( is_wp_error( $result ) ) { + // @todo Reset note actioned status? + return; + } + + $installer->activate_plugin( $plugin ); + } + } +}