diff --git a/src/utils/FrontendFilesLoader.php b/src/utils/FrontendFilesLoader.php index ce4eb1c3..404ccb7e 100644 --- a/src/utils/FrontendFilesLoader.php +++ b/src/utils/FrontendFilesLoader.php @@ -111,22 +111,24 @@ public function enqueue_inputmask_scripts() '); } - public function check_for_subscription_in_order() { + public function check_for_subscription_in_order() + { global $post; - if ($post->post_type === 'shop_order' || $post->post_type === 'shop_subscription') { + if ($this->is_shop_order_or_subscription($post)) { $order = wc_get_order($post->ID); $has_subscription = false; $subscriptions_product = new WC_Subscriptions_Product(); - foreach ($order->get_items() as $item_id => $item) { + foreach ($order->get_items() as $item) { if ($subscriptions_product->is_subscription($item->get_product())) { $has_subscription = true; break; } } - - wp_register_script('notification-js', plugins_url('/assets/js/notification.js', plugin_dir_path(__FILE__)), array('jquery'), VINDI_VERSION, true); + + $dir_path = plugins_url('/assets/js/notification.js', plugin_dir_path(__FILE__)); + wp_register_script('notification-js', $dir_path, array('jquery'), VINDI_VERSION, true); wp_enqueue_script('notification-js'); wp_localize_script('notification-js', 'orderData', array( @@ -134,4 +136,9 @@ public function check_for_subscription_in_order() { )); } } + + private function is_shop_order_or_subscription($post) + { + return $post->post_type === 'shop_order' || $post->post_type === 'shop_subscription'; + } }