Issues (575)

classes/class-woocommerce.php (33 issues)

1
<?php
2
/**
3
 * LSX Currency Frontend Class
4
 *
5
 * @package   LSX Currencies
6
 * @author    LightSpeed
7
 * @license   GPL3
8
 * @link
9
 * @copyright 2019 LightSpeed
10
 */
11
12
namespace lsx\currencies\classes;
13
14
/**
15
 * Holds the WooCommerce Integrations
16
 */
17
class WooCommerce {
18
19
	/**
20
	 * Holds instance of the class
21
	 *
22
	 * @var object \lsx\currencies\classes\WooCommerce()
23
	 */
24
	private static $instance;
25
26
	/**
27
	 * Holds the current currency.
28
	 *
29
	 * @var boolean
30
	 */
31
	public $currency = false;
32
33
	/**
34
	 * Constructor
35
	 */
36
	public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
37
		add_filter( 'wc_price', array( $this, 'price_filter' ), 300, 3 );
38
		add_filter( 'lsx_currencies_base_currency', array( $this, 'set_base_currency' ), 10, 1 );
39
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
40
41
	/**
42
	 * Return an instance of this class.
43
	 *
44
	 * @return  object
45
	 */
46
	public static function init() {
47
		// If the single instance hasn't been set, set it now.
48
		if ( ! isset( self::$instance ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
49
			self::$instance = new self();
50
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
51
		return self::$instance;
52
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
53
54
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$return" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$price" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$args" missing
Loading history...
55
	 * Filter the WooCommerce Price.
56
	 *
57
	 * @param $return mixed
0 ignored issues
show
Missing parameter name
Loading history...
58
	 * @param $price string
0 ignored issues
show
Missing parameter name
Loading history...
59
	 * @param $args array
0 ignored issues
show
Missing parameter name
Loading history...
60
	 *
61
	 * @return mixed
62
	 */
63
	public function price_filter( $return, $price, $args ) {
64
		if ( '' !== $price ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
65
			$return = str_replace( 'class', 'data-price-' . lsx_currencies()->base_currency . '=' . $price . ' class', $return );
66
			$return = str_replace( 'woocommerce-Price-amount', 'woocommerce-Price-amount lsx-currencies', $return );
67
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
68
		return $return;
69
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
70
71
	/**
0 ignored issues
show
Missing short description in doc comment
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$cart_subtotal" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$compound" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$obj" missing
Loading history...
72
	 * @param $cart_subtotal
0 ignored issues
show
Missing parameter name
Loading history...
73
	 * @param $compound
0 ignored issues
show
Missing parameter name
Loading history...
74
	 * @param $obj
0 ignored issues
show
Missing parameter name
Loading history...
75
	 *
76
	 * @return mixed
77
	 */
78
	public function cart_subtotal( $cart_subtotal, $compound, $obj ) {
0 ignored issues
show
Expected 0 blank lines after opening function brace; 1 found
Loading history...
79
80
		$return = str_replace( 'class', 'data-price-' . $this->currency . '=' . $price . ' class', $return );
81
		$return = str_replace( 'woocommerce-Price-amount', 'woocommerce-Price-amount lsx-currencies', $return );
82
83
		return $cart_subtotal;
84
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
85
86
	/**
87
	 * Make sure our base currency is set to the same as woocommerce.
88
	 *
89
	 * @param string $currency
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
90
	 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
91
	 */
92
	public function set_base_currency( $currency ) {
93
		return get_woocommerce_currency();
94
	}
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
95
}
96