woocommerce/plugins/woocommerce-admin/src/Notes/AddFirstProduct.php

91 lines
2.7 KiB
PHP
Raw Normal View History

Add merchant email notifications (https://github.com/woocommerce/woocommerce-admin/pull/5922) * Added MerchantEmailNotifications class * Added new type and Events refactor # Conflicts: # src/Events.php * Added templates * Refactored MerchantEmailNotifications and NotificationEmail * Templates refactored * Added email opening tracking endpoint * Added templates handling * Moved folder `MerchantEmailNotifications` * Fixed template extensibility * Fixed note `heading` check * Added default type in `get_template_filename` * Added tests * Removed bypass * Modified URL * Added required noteTypes * Added flag for functionallity * Fixed plain link * Fixed comment * Turned email notifications on by default This commit adds the code to turn email notifications on by default * Fixed email styles * Fixed typo * Renamed method "possible_send" as "run" * Removed unnecessary control * Fixed another typo * Renamed method as "get_notification_email_addresses" * Refactored method "send_merchant_notification" * Renamed plain-merchant-notification * Fixed tests * Merchant email notifications - Action triggering (https://github.com/woocommerce/woocommerce-admin/pull/5976) * Added templates # Conflicts: # includes/emails/plain-mechant-notification.php # Conflicts: # includes/emails/html-merchant-notification.php * Added note action triggering This commit adds the note actions triggering # Conflicts: # includes/emails/html-merchant-notification.php * Fixed error handling * Refactored "trigger_note_action" method * Fixed actions url * Fixed note URL * Added external redirect * Added image and html handling for email * Fixed tests * Fixed buttons style Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Add your first product: email notification (https://github.com/woocommerce/woocommerce-admin/pull/6024) * Added AddFirstProduct note # Conflicts: # src/Events.php * Added "AddFirstProduct" email note This commit adds the email note "AddFirstProduct" * Fixed image This commit removes the image img-product-light.svg to use a png instead. Otherwise, the gmail proxy would break the image * Fixed readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Added readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2021-01-13 00:09:22 +00:00
<?php
/**
* WooCommerce Admin: Add First Product.
*
* Adds a note (type `email`) to bring the client back to the store setup flow.
*/
namespace Automattic\WooCommerce\Admin\Notes;
defined( 'ABSPATH' ) || exit;
/**
* Add_First_Product.
*/
class AddFirstProduct {
/**
* Note traits.
*/
use NoteTraits;
/**
* Name of the note for use in the database.
*/
const NOTE_NAME = 'wc-admin-add-first-product-note';
/**
* Get the note.
*
* @return Note
*/
public static function get_note() {
if ( ! self::wc_admin_active_for( 2 * DAY_IN_SECONDS ) || self::wc_admin_active_for( 5 * DAY_IN_SECONDS ) ) {
Add merchant email notifications (https://github.com/woocommerce/woocommerce-admin/pull/5922) * Added MerchantEmailNotifications class * Added new type and Events refactor # Conflicts: # src/Events.php * Added templates * Refactored MerchantEmailNotifications and NotificationEmail * Templates refactored * Added email opening tracking endpoint * Added templates handling * Moved folder `MerchantEmailNotifications` * Fixed template extensibility * Fixed note `heading` check * Added default type in `get_template_filename` * Added tests * Removed bypass * Modified URL * Added required noteTypes * Added flag for functionallity * Fixed plain link * Fixed comment * Turned email notifications on by default This commit adds the code to turn email notifications on by default * Fixed email styles * Fixed typo * Renamed method "possible_send" as "run" * Removed unnecessary control * Fixed another typo * Renamed method as "get_notification_email_addresses" * Refactored method "send_merchant_notification" * Renamed plain-merchant-notification * Fixed tests * Merchant email notifications - Action triggering (https://github.com/woocommerce/woocommerce-admin/pull/5976) * Added templates # Conflicts: # includes/emails/plain-mechant-notification.php # Conflicts: # includes/emails/html-merchant-notification.php * Added note action triggering This commit adds the note actions triggering # Conflicts: # includes/emails/html-merchant-notification.php * Fixed error handling * Refactored "trigger_note_action" method * Fixed actions url * Fixed note URL * Added external redirect * Added image and html handling for email * Fixed tests * Fixed buttons style Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Add your first product: email notification (https://github.com/woocommerce/woocommerce-admin/pull/6024) * Added AddFirstProduct note # Conflicts: # src/Events.php * Added "AddFirstProduct" email note This commit adds the email note "AddFirstProduct" * Fixed image This commit removes the image img-product-light.svg to use a png instead. Otherwise, the gmail proxy would break the image * Fixed readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Added readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2021-01-13 00:09:22 +00:00
return;
}
// Don't show if there is a product.
$query = new \WC_Product_Query(
array(
'limit' => 1,
'return' => 'ids',
'status' => array( 'publish' ),
)
);
$products = $query->get_products();
if ( 0 !== count( $products ) ) {
return;
}
// Don't show if there is an orders.
$args = array(
'limit' => 1,
'return' => 'ids',
);
$orders = wc_get_orders( $args );
if ( 0 !== count( $orders ) ) {
return;
}
// If you're updating the following please use sprintf to separate HTML tags.
// https://github.com/woocommerce/woocommerce-admin/pull/6617#discussion_r596889685.
Add merchant email notifications (https://github.com/woocommerce/woocommerce-admin/pull/5922) * Added MerchantEmailNotifications class * Added new type and Events refactor # Conflicts: # src/Events.php * Added templates * Refactored MerchantEmailNotifications and NotificationEmail * Templates refactored * Added email opening tracking endpoint * Added templates handling * Moved folder `MerchantEmailNotifications` * Fixed template extensibility * Fixed note `heading` check * Added default type in `get_template_filename` * Added tests * Removed bypass * Modified URL * Added required noteTypes * Added flag for functionallity * Fixed plain link * Fixed comment * Turned email notifications on by default This commit adds the code to turn email notifications on by default * Fixed email styles * Fixed typo * Renamed method "possible_send" as "run" * Removed unnecessary control * Fixed another typo * Renamed method as "get_notification_email_addresses" * Refactored method "send_merchant_notification" * Renamed plain-merchant-notification * Fixed tests * Merchant email notifications - Action triggering (https://github.com/woocommerce/woocommerce-admin/pull/5976) * Added templates # Conflicts: # includes/emails/plain-mechant-notification.php # Conflicts: # includes/emails/html-merchant-notification.php * Added note action triggering This commit adds the note actions triggering # Conflicts: # includes/emails/html-merchant-notification.php * Fixed error handling * Refactored "trigger_note_action" method * Fixed actions url * Fixed note URL * Added external redirect * Added image and html handling for email * Fixed tests * Fixed buttons style Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Add your first product: email notification (https://github.com/woocommerce/woocommerce-admin/pull/6024) * Added AddFirstProduct note # Conflicts: # src/Events.php * Added "AddFirstProduct" email note This commit adds the email note "AddFirstProduct" * Fixed image This commit removes the image img-product-light.svg to use a png instead. Otherwise, the gmail proxy would break the image * Fixed readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Added readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2021-01-13 00:09:22 +00:00
$content_lines = array(
'{greetings}<br/><br/>',
/* translators: %s: line break */
sprintf( __( 'Nice one; you\'ve created a WooCommerce store! Now it\'s time to add your first product and get ready to start selling.%s', 'woocommerce-admin' ), '<br/><br/>' ),
Add merchant email notifications (https://github.com/woocommerce/woocommerce-admin/pull/5922) * Added MerchantEmailNotifications class * Added new type and Events refactor # Conflicts: # src/Events.php * Added templates * Refactored MerchantEmailNotifications and NotificationEmail * Templates refactored * Added email opening tracking endpoint * Added templates handling * Moved folder `MerchantEmailNotifications` * Fixed template extensibility * Fixed note `heading` check * Added default type in `get_template_filename` * Added tests * Removed bypass * Modified URL * Added required noteTypes * Added flag for functionallity * Fixed plain link * Fixed comment * Turned email notifications on by default This commit adds the code to turn email notifications on by default * Fixed email styles * Fixed typo * Renamed method "possible_send" as "run" * Removed unnecessary control * Fixed another typo * Renamed method as "get_notification_email_addresses" * Refactored method "send_merchant_notification" * Renamed plain-merchant-notification * Fixed tests * Merchant email notifications - Action triggering (https://github.com/woocommerce/woocommerce-admin/pull/5976) * Added templates # Conflicts: # includes/emails/plain-mechant-notification.php # Conflicts: # includes/emails/html-merchant-notification.php * Added note action triggering This commit adds the note actions triggering # Conflicts: # includes/emails/html-merchant-notification.php * Fixed error handling * Refactored "trigger_note_action" method * Fixed actions url * Fixed note URL * Added external redirect * Added image and html handling for email * Fixed tests * Fixed buttons style Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Add your first product: email notification (https://github.com/woocommerce/woocommerce-admin/pull/6024) * Added AddFirstProduct note # Conflicts: # src/Events.php * Added "AddFirstProduct" email note This commit adds the email note "AddFirstProduct" * Fixed image This commit removes the image img-product-light.svg to use a png instead. Otherwise, the gmail proxy would break the image * Fixed readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Added readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2021-01-13 00:09:22 +00:00
__( 'There are three ways to add your products: you can <strong>create products manually, import them at once via CSV file</strong>, or <strong>migrate them from another service</strong>.<br/><br/>', 'woocommerce-admin' ),
/* translators: %1$s is an open anchor tag (<a>) and %2$s is a close link tag (</a>). */
sprintf( __( '%1$1sExplore our docs%2$2s for more information, or just get started!', 'woocommerce-admin' ), '<a href="https://woocommerce.com/document/managing-products/?utm_source=help_panel&utm_medium=product">', '</a>' ),
Add merchant email notifications (https://github.com/woocommerce/woocommerce-admin/pull/5922) * Added MerchantEmailNotifications class * Added new type and Events refactor # Conflicts: # src/Events.php * Added templates * Refactored MerchantEmailNotifications and NotificationEmail * Templates refactored * Added email opening tracking endpoint * Added templates handling * Moved folder `MerchantEmailNotifications` * Fixed template extensibility * Fixed note `heading` check * Added default type in `get_template_filename` * Added tests * Removed bypass * Modified URL * Added required noteTypes * Added flag for functionallity * Fixed plain link * Fixed comment * Turned email notifications on by default This commit adds the code to turn email notifications on by default * Fixed email styles * Fixed typo * Renamed method "possible_send" as "run" * Removed unnecessary control * Fixed another typo * Renamed method as "get_notification_email_addresses" * Refactored method "send_merchant_notification" * Renamed plain-merchant-notification * Fixed tests * Merchant email notifications - Action triggering (https://github.com/woocommerce/woocommerce-admin/pull/5976) * Added templates # Conflicts: # includes/emails/plain-mechant-notification.php # Conflicts: # includes/emails/html-merchant-notification.php * Added note action triggering This commit adds the note actions triggering # Conflicts: # includes/emails/html-merchant-notification.php * Fixed error handling * Refactored "trigger_note_action" method * Fixed actions url * Fixed note URL * Added external redirect * Added image and html handling for email * Fixed tests * Fixed buttons style Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Add your first product: email notification (https://github.com/woocommerce/woocommerce-admin/pull/6024) * Added AddFirstProduct note # Conflicts: # src/Events.php * Added "AddFirstProduct" email note This commit adds the email note "AddFirstProduct" * Fixed image This commit removes the image img-product-light.svg to use a png instead. Otherwise, the gmail proxy would break the image * Fixed readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Added readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2021-01-13 00:09:22 +00:00
);
$additional_data = array(
'role' => 'administrator',
);
$note = new Note();
$note->set_title( __( 'Add your first product', 'woocommerce-admin' ) );
Add merchant email notifications (https://github.com/woocommerce/woocommerce-admin/pull/5922) * Added MerchantEmailNotifications class * Added new type and Events refactor # Conflicts: # src/Events.php * Added templates * Refactored MerchantEmailNotifications and NotificationEmail * Templates refactored * Added email opening tracking endpoint * Added templates handling * Moved folder `MerchantEmailNotifications` * Fixed template extensibility * Fixed note `heading` check * Added default type in `get_template_filename` * Added tests * Removed bypass * Modified URL * Added required noteTypes * Added flag for functionallity * Fixed plain link * Fixed comment * Turned email notifications on by default This commit adds the code to turn email notifications on by default * Fixed email styles * Fixed typo * Renamed method "possible_send" as "run" * Removed unnecessary control * Fixed another typo * Renamed method as "get_notification_email_addresses" * Refactored method "send_merchant_notification" * Renamed plain-merchant-notification * Fixed tests * Merchant email notifications - Action triggering (https://github.com/woocommerce/woocommerce-admin/pull/5976) * Added templates # Conflicts: # includes/emails/plain-mechant-notification.php # Conflicts: # includes/emails/html-merchant-notification.php * Added note action triggering This commit adds the note actions triggering # Conflicts: # includes/emails/html-merchant-notification.php * Fixed error handling * Refactored "trigger_note_action" method * Fixed actions url * Fixed note URL * Added external redirect * Added image and html handling for email * Fixed tests * Fixed buttons style Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Add your first product: email notification (https://github.com/woocommerce/woocommerce-admin/pull/6024) * Added AddFirstProduct note # Conflicts: # src/Events.php * Added "AddFirstProduct" email note This commit adds the email note "AddFirstProduct" * Fixed image This commit removes the image img-product-light.svg to use a png instead. Otherwise, the gmail proxy would break the image * Fixed readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Added readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2021-01-13 00:09:22 +00:00
$note->set_content( implode( '', $content_lines ) );
$note->set_content_data( (object) $additional_data );
$note->set_image(
plugins_url(
'/images/admin_notes/dashboard-widget-setup.png',
Add merchant email notifications (https://github.com/woocommerce/woocommerce-admin/pull/5922) * Added MerchantEmailNotifications class * Added new type and Events refactor # Conflicts: # src/Events.php * Added templates * Refactored MerchantEmailNotifications and NotificationEmail * Templates refactored * Added email opening tracking endpoint * Added templates handling * Moved folder `MerchantEmailNotifications` * Fixed template extensibility * Fixed note `heading` check * Added default type in `get_template_filename` * Added tests * Removed bypass * Modified URL * Added required noteTypes * Added flag for functionallity * Fixed plain link * Fixed comment * Turned email notifications on by default This commit adds the code to turn email notifications on by default * Fixed email styles * Fixed typo * Renamed method "possible_send" as "run" * Removed unnecessary control * Fixed another typo * Renamed method as "get_notification_email_addresses" * Refactored method "send_merchant_notification" * Renamed plain-merchant-notification * Fixed tests * Merchant email notifications - Action triggering (https://github.com/woocommerce/woocommerce-admin/pull/5976) * Added templates # Conflicts: # includes/emails/plain-mechant-notification.php # Conflicts: # includes/emails/html-merchant-notification.php * Added note action triggering This commit adds the note actions triggering # Conflicts: # includes/emails/html-merchant-notification.php * Fixed error handling * Refactored "trigger_note_action" method * Fixed actions url * Fixed note URL * Added external redirect * Added image and html handling for email * Fixed tests * Fixed buttons style Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Add your first product: email notification (https://github.com/woocommerce/woocommerce-admin/pull/6024) * Added AddFirstProduct note # Conflicts: # src/Events.php * Added "AddFirstProduct" email note This commit adds the email note "AddFirstProduct" * Fixed image This commit removes the image img-product-light.svg to use a png instead. Otherwise, the gmail proxy would break the image * Fixed readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> * Added readme.txt Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
2021-01-13 00:09:22 +00:00
WC_ADMIN_PLUGIN_FILE
)
);
$note->set_type( Note::E_WC_ADMIN_NOTE_EMAIL );
$note->set_name( self::NOTE_NAME );
$note->set_source( 'woocommerce-admin' );
$note->add_action( 'add-first-product', __( 'Add a product', 'woocommerce-admin' ), admin_url( 'admin.php?page=wc-admin&task=products' ) );
return $note;
}
}