Skip to content

Commit 05d4000

Browse files
Merge pull request #491 from Codeinwp/bugfix/pro/597
Fixed load JS script dependencies for latest WC version
2 parents f288273 + b35c948 commit 05d4000

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

classes/frontend-scripts.class.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static function init() {
5252
private static function get_scripts() {
5353

5454
$ppom_price_js = ppom_get_price_table_calculation();
55+
$dependencies = ppom_get_price_table_js_dependencies();
5556

5657
$register_scripts = array(
5758
'PPOM-sm-popup' => array(
@@ -71,7 +72,7 @@ private static function get_scripts() {
7172
),
7273
'ppom-price' => array(
7374
'src' => self::$scripts_url . "/js/price/{$ppom_price_js}",
74-
'deps' => array( 'jquery', 'ppom-inputs', 'accounting' ),
75+
'deps' => $dependencies,
7576
'version' => self::$version,
7677
),
7778
'ppom-inputmask' => array(

inc/functions.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,6 +2178,23 @@ function ppom_get_price_table_calculation() {
21782178
return apply_filters( 'ppom_price_table_script', $js_script );
21792179
}
21802180

2181+
/**
2182+
* Get price table JS dependencies.
2183+
*
2184+
* @return string[]
2185+
*/
2186+
function ppom_get_price_table_js_dependencies() {
2187+
$dependencies = array( 'jquery', 'ppom-inputs' );
2188+
2189+
if ( version_compare( WC_VERSION, '10.3.0', '<' ) ) {
2190+
$dependencies[] = 'accounting';
2191+
} else{
2192+
$dependencies[] = 'wc-accounting';
2193+
}
2194+
2195+
return $dependencies;
2196+
}
2197+
21812198
function ppom_get_price_table_location() {
21822199

21832200
$location = ppom_get_option( 'ppom_price_table_location', 'after' );

inc/hooks.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,11 @@ function ppom_hooks_load_input_scripts( $product, $ppom_id = null ) {
218218

219219
// Price display controller
220220
$ppom_price_js = ppom_get_price_table_calculation();
221+
$dependencies = ppom_get_price_table_js_dependencies();
221222
wp_enqueue_script(
222223
'ppom-price',
223224
PPOM_URL . "/js/price/{$ppom_price_js}",
224-
array(
225-
'jquery',
226-
'ppom-inputs',
227-
'accounting',
228-
),
225+
$dependencies,
229226
PPOM_VERSION,
230227
true
231228
);

phpstan-baseline.neon

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4110,11 +4110,6 @@ parameters:
41104110
count: 1
41114111
path: inc/functions.php
41124112

4113-
-
4114-
message: "#^If condition is always true\\.$#"
4115-
count: 1
4116-
path: inc/functions.php
4117-
41184113
-
41194114
message: "#^Parameter \\#1 \\$text of function esc_attr expects string, int\\<0, max\\> given\\.$#"
41204115
count: 1
@@ -4592,7 +4587,7 @@ parameters:
45924587

45934588
-
45944589
message: "#^If condition is always true\\.$#"
4595-
count: 2
4590+
count: 1
45964591
path: inc/hooks.php
45974592

45984593
-

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
parameters:
22
level: 6
3+
dynamicConstantNames:
4+
- WC_VERSION
35
paths:
46
- %currentWorkingDirectory%/inc
57
- %currentWorkingDirectory%/classes

0 commit comments

Comments
 (0)