From c8de6b97bed74b0563303a2a4ea746305c16d3fd Mon Sep 17 00:00:00 2001 From: Jason Conroy Date: Wed, 15 Jul 2020 15:45:20 +0930 Subject: [PATCH] Add WooCommerce Admin Facebook Marketing Expert Note Provider. (https://github.com/woocommerce/woocommerce-admin/pull/4787) * Add WooCommerce Admin Facebook Marketing Expert Note Provider. * Fix number of orders and move cheaper check to be first * Update title * Update note title and copy * Adjust orders_last_month check * Return ids to speed up query * Use PluginsHelper --- plugins/woocommerce-admin/src/Events.php | 2 + ..._Admin_Notes_Facebook_Marketing_Expert.php | 109 ++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Marketing_Expert.php diff --git a/plugins/woocommerce-admin/src/Events.php b/plugins/woocommerce-admin/src/Events.php index 3573553253a..28dfcdb4fe8 100644 --- a/plugins/woocommerce-admin/src/Events.php +++ b/plugins/woocommerce-admin/src/Events.php @@ -36,6 +36,7 @@ use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Learn_More_About_Product_ use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Online_Clothing_Store; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_First_Product; use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Customize_Store_With_Blocks; +use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Facebook_Marketing_Expert; /** * WC_Admin_Events Class. @@ -103,6 +104,7 @@ class Events { WC_Admin_Notes_Choose_Niche::possibly_add_note(); WC_Admin_Notes_Real_Time_Order_Alerts::possibly_add_note(); WC_Admin_Notes_Customize_Store_With_Blocks::possibly_add_note(); + WC_Admin_Notes_Facebook_Marketing_Expert::possibly_add_note(); if ( Loader::is_feature_enabled( 'remote-inbox-notifications' ) ) { DataSourcePoller::read_specs_from_data_sources(); diff --git a/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Marketing_Expert.php b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Marketing_Expert.php new file mode 100644 index 00000000000..82e51175ea3 --- /dev/null +++ b/plugins/woocommerce-admin/src/Notes/WC_Admin_Notes_Facebook_Marketing_Expert.php @@ -0,0 +1,109 @@ +save(); + } + + /** + * Get the note. + */ + public static function get_note() { + $note = new WC_Admin_Note(); + $note->set_title( __( 'Create and optimise your Facebook ads with the help of a Facebook Marketing Expert', 'woocommerce-admin' ) ); + $note->set_content( __( 'Get 1:1 business support from a Facebook Marketing Expert who will work with you and your business to create and optimize your Facebook ads. Discover new strategies used by similar businesses in your market and industry. Check whether you are eligible to make use of this offer.', 'woocommerce-admin' ) ); + $note->set_type( WC_Admin_Note::E_WC_ADMIN_NOTE_INFORMATIONAL ); + $note->set_name( self::NOTE_NAME ); + $note->set_content_data( (object) array() ); + $note->set_source( 'woocommerce-admin' ); + $note->add_action( + 'learn-more', + __( 'Learn more', 'woocommerce-admin' ), + 'https://www.facebook.com/business/m/facebook-marketing-experts-program?content_id=UxWvEceBNtpQLhU', + WC_Admin_Note::E_WC_ADMIN_NOTE_ACTIONED, + true + ); + return $note; + } + + /** + * Determine if Facebook for WooCommerce is already active or installed + * + * @return bool + */ + protected static function is_facebook_for_woocommerce_installed() { + if ( class_exists( 'WC_Facebookcommerce_Integration' ) ) { + return true; + } + return PluginsHelper::is_plugin_installed( self::PLUGIN_FILE ); + } + + /** + * Determine the number of orders in the last month + * + * @return int + */ + protected static function orders_last_month() { + + $date = new \DateTime(); + + $args = array( + 'date_created' => '>' . $date->modify( '-1 month' )->format( 'Y-m-d' ), + 'return' => 'ids', + ); + + return count( wc_get_orders( $args ) ); + } +}