/var/www/html_us/wp-content/plugins/woocommerce/src/Internal/Admin/Notes/AddFirstProduct.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
 * WooCommerce Admin: Add First Product.
 *
 * Adds a note (type `email`) to bring the client back to the store setup flow.
 */

namespace Automattic\WooCommerce\Internal\Admin\Notes;

defined'ABSPATH' ) || exit;

use 
Automattic\WooCommerce\Admin\Notes\Note;
use 
Automattic\WooCommerce\Admin\Notes\NoteTraits;
use 
Automattic\WooCommerce\Enums\ProductStatus;

/**
 * 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_forDAY_IN_SECONDS ) || self::wc_admin_active_forDAY_IN_SECONDS ) ) {
            return;
        }

        
// Don't show if there is a product.
        
$query    = new \WC_Product_Query(
            array(
                
'limit'  => 1,
                
'return' => 'ids',
                
'status' => array( ProductStatus::PUBLISH ),
            )
        );
        
$products $query->get_products();
        if ( 
!== count$products ) ) {
            return;
        }

        
// Don't show if there is an orders.
        
$args   = array(
            
'limit'  => 1,
            
'return' => 'ids',
        );
        
$orders wc_get_orders$args );
        if ( 
!== 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.
        
$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' ), '<br/><br/>' ),
            
__'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' ),
            
/* 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' ), '<a href="https://woocommerce.com/document/managing-products/?utm_source=help_panel&utm_medium=product">''</a>' ),
        );

        
$additional_data = array(
            
'role' => 'administrator',
        );

        
$note = new Note();
        
$note->set_title__'Add your first product''woocommerce' ) );
        
$note->set_contentimplode''$content_lines ) );
        
$note->set_content_data( (object) $additional_data );
        
$note->set_image(
            
plugins_url(
                
'/images/admin_notes/dashboard-widget-setup.png',
                
WC_ADMIN_PLUGIN_FILE
            
)
        );
        
$note->set_typeNote::E_WC_ADMIN_NOTE_EMAIL );
        
$note->set_nameself::NOTE_NAME );
        
$note->set_source'woocommerce-admin' );
        
$note->add_action'add-first-product'__'Add a product''woocommerce' ), admin_url'admin.php?page=wc-admin&task=products' ) );
        return 
$note;
    }
}