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
This commit is contained in:
Jason Conroy 2020-07-15 15:45:20 +09:30 committed by GitHub
parent 88ab1cf285
commit c8de6b97be
2 changed files with 111 additions and 0 deletions

View File

@ -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_Online_Clothing_Store;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_First_Product; 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_Customize_Store_With_Blocks;
use \Automattic\WooCommerce\Admin\Notes\WC_Admin_Notes_Facebook_Marketing_Expert;
/** /**
* WC_Admin_Events Class. * WC_Admin_Events Class.
@ -103,6 +104,7 @@ class Events {
WC_Admin_Notes_Choose_Niche::possibly_add_note(); WC_Admin_Notes_Choose_Niche::possibly_add_note();
WC_Admin_Notes_Real_Time_Order_Alerts::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_Customize_Store_With_Blocks::possibly_add_note();
WC_Admin_Notes_Facebook_Marketing_Expert::possibly_add_note();
if ( Loader::is_feature_enabled( 'remote-inbox-notifications' ) ) { if ( Loader::is_feature_enabled( 'remote-inbox-notifications' ) ) {
DataSourcePoller::read_specs_from_data_sources(); DataSourcePoller::read_specs_from_data_sources();

View File

@ -0,0 +1,109 @@
<?php
/**
* WooCommerce Admin Facebook Marketing Expert Note Provider.
*
* Adds notes to the merchant's inbox concerning Facebook Marketing Expert.
*
* @package WooCommerce Admin
*/
namespace Automattic\WooCommerce\Admin\Notes;
defined( 'ABSPATH' ) || exit;
use \Automattic\WooCommerce\Admin\PluginsHelper;
/**
* WC_Admin_Notes_Facebook_Marketing_Expert
*/
class WC_Admin_Notes_Facebook_Marketing_Expert {
/**
* Note traits.
*/
use NoteTraits;
/**
* Name of the note for use in the database.
*/
const NOTE_NAME = 'wc-admin-facebook-marketing-expert';
/**
* Name of plugin file.
*/
const PLUGIN_FILE = 'facebook-for-woocommerce/facebook-for-woocommerce.php';
/**
* Possibly add note.
*/
public static function possibly_add_note() {
// Check if the note can and should be added.
if ( ! self::can_be_added() ) {
return;
}
// Only add the note to stores with Facebook for WooCommerce installed.
if ( ! self::is_facebook_for_woocommerce_installed() ) {
return;
}
// Only add the note to stores with at least 30 orders in the last month.
if ( self::orders_last_month() < 30 ) {
return;
}
$note = self::get_note();
$note->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 ) );
}
}