/var/www/html_uk/wp-content/plugins/automatewoo/includes/Actions/Subscription_Add_Note.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
<?php

namespace AutomateWoo;

if ( ! 
defined'ABSPATH' ) ) {
    exit;
}

/**
 * Action for adding a note to a Subscription.
 *
 * @class Action_Subscription_Add_Note
 * @since 4.6.0
 */
class Action_Subscription_Add_Note extends Action_Order_Add_Note {

    
/**
     * Data items required for the action to run.
     *
     * @var array
     */
    
public $required_data_items = [ 'subscription' ];

    
/**
     * Method to set title, group, description and other admin props.
     */
    
public function load_admin_details() {
        
$this->title __'Add Note''automatewoo' );
        
$this->group __'Subscription''automatewoo' );
    }

    
/**
     * Called when an action should be run.
     */
    
public function run() {
        
$note_type    $this->get_option'note_type' );
        
$author       $this->get_option'note_author' );
        
$note         $this->get_option'note'true );
        
$subscription $this->workflow->data_layer()->get_subscription();

        if ( ! 
$note || ! $note_type || ! $subscription ) {
            return;
        }

        
$should_set_custom_author = ! empty( $author ) && is_string$author );

        if ( 
$should_set_custom_author ) {
            
$this->add_custom_author$author );
        }

        
$subscription->add_order_note$note'customer' === $note_typefalse );

        if ( 
$should_set_custom_author ) {
            
$this->remove_custom_author();
        }
    }
}