From 6995c075fc1b427cd13fc8b423031a469f46bb72 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Mon, 27 Oct 2025 12:20:12 +0530 Subject: [PATCH 1/2] fix: load JS script dependencies for latest WC version --- classes/frontend-scripts.class.php | 3 ++- inc/functions.php | 18 ++++++++++++++++++ inc/hooks.php | 7 ++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/classes/frontend-scripts.class.php b/classes/frontend-scripts.class.php index dcdd6b60..2519fdb3 100644 --- a/classes/frontend-scripts.class.php +++ b/classes/frontend-scripts.class.php @@ -52,6 +52,7 @@ public static function init() { private static function get_scripts() { $ppom_price_js = ppom_get_price_table_calculation(); + $dependencies = ppom_get_price_table_js_dependencies(); $register_scripts = array( 'PPOM-sm-popup' => array( @@ -71,7 +72,7 @@ private static function get_scripts() { ), 'ppom-price' => array( 'src' => self::$scripts_url . "/js/price/{$ppom_price_js}", - 'deps' => array( 'jquery', 'ppom-inputs', 'accounting' ), + 'deps' => $dependencies, 'version' => self::$version, ), 'ppom-inputmask' => array( diff --git a/inc/functions.php b/inc/functions.php index c4d276dd..16797327 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2178,6 +2178,24 @@ function ppom_get_price_table_calculation() { return apply_filters( 'ppom_price_table_script', $js_script ); } +/** + * Get price table JS dependencies. + * + * @return string[] + */ +function ppom_get_price_table_js_dependencies() { + $dependencies = array( 'jquery', 'ppom-inputs' ); + + // @phpstan-ignore-next-line + if ( version_compare( WC_VERSION, '10.3.0', '<' ) ) { + $dependencies[] = 'accounting'; + } else{ + $dependencies[] = 'wc-accounting'; + } + + return $dependencies; +} + function ppom_get_price_table_location() { $location = ppom_get_option( 'ppom_price_table_location', 'after' ); diff --git a/inc/hooks.php b/inc/hooks.php index 3dee3ea2..bdea3e04 100644 --- a/inc/hooks.php +++ b/inc/hooks.php @@ -218,14 +218,11 @@ function ppom_hooks_load_input_scripts( $product, $ppom_id = null ) { // Price display controller $ppom_price_js = ppom_get_price_table_calculation(); + $dependencies = ppom_get_price_table_js_dependencies(); wp_enqueue_script( 'ppom-price', PPOM_URL . "/js/price/{$ppom_price_js}", - array( - 'jquery', - 'ppom-inputs', - 'accounting', - ), + $dependencies, PPOM_VERSION, true ); From b35c948b80576acd669de19d22f5747d8501185f Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Mon, 27 Oct 2025 14:08:22 +0530 Subject: [PATCH 2/2] fix:phpstan --- inc/functions.php | 1 - phpstan-baseline.neon | 7 +------ phpstan.neon | 2 ++ 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 16797327..c58e77e1 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2186,7 +2186,6 @@ function ppom_get_price_table_calculation() { function ppom_get_price_table_js_dependencies() { $dependencies = array( 'jquery', 'ppom-inputs' ); - // @phpstan-ignore-next-line if ( version_compare( WC_VERSION, '10.3.0', '<' ) ) { $dependencies[] = 'accounting'; } else{ diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cdeedbe4..d1073f15 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4110,11 +4110,6 @@ parameters: count: 1 path: inc/functions.php - - - message: "#^If condition is always true\\.$#" - count: 1 - path: inc/functions.php - - message: "#^Parameter \\#1 \\$text of function esc_attr expects string, int\\<0, max\\> given\\.$#" count: 1 @@ -4592,7 +4587,7 @@ parameters: - message: "#^If condition is always true\\.$#" - count: 2 + count: 1 path: inc/hooks.php - diff --git a/phpstan.neon b/phpstan.neon index bb7b04f4..42d00a3b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,7 @@ parameters: level: 6 + dynamicConstantNames: + - WC_VERSION paths: - %currentWorkingDirectory%/inc - %currentWorkingDirectory%/classes