/var/www/html_uk/wp-content/plugins/automatewoo/includes/Fields/Price.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
<?php
// phpcs:ignoreFile

namespace AutomateWoo\Fields;

use 
AutomateWoo\Clean;

if ( ! 
defined'ABSPATH' ) ) exit;

/**
 * @class Price
 */
class Price extends Text {

    protected 
$name 'price';

    protected 
$type 'text';


    function 
__construct() {
        
parent::__construct();

        
$this->set_title__'Price''automatewoo' ) );
        
$this->classes[] = 'automatewoo-field--type-price';
    }

    
/**
     * Sanitizes the field value.
     *
     * Removes currency symbols, thousand separators and sets correct decimal places.
     * Empty string values are deliberately allowed.
     *
     * @since 4.4.0
     * @since 4.6.0 Adds support for workflow variables.
     *
     * @param string $value
     *
     * @return string
     */
    
public function sanitize_value$value ) {
        
$value trim$value );

        
// preserve empty string values, don't convert to '0.00'
        
if ( $value === '' ) {
            return 
'';
        }

        if ( 
false === strpos$value'{{' ) ) {
            
// IMPORTANT - Must clean the price value to convert from a localized format
            
return Clean::localized_price$value );
        } else {
            return 
Clean::string$value );
        }
    }

    
/**
     * Output the field HTML.
     *
     * @param string $value
     */
    
public function render$value ) {
        
// If not a variable localize the price value
        
if ( false === strpos$value'{{' ) ) {
            
$value wc_format_localized_price$value );
        }
        
parent::render$value );
    }
}