check_eligible_country()) { return; } if (! $this->check_was_enabled_config()) { return; } add_action('admin_enqueue_scripts', [$this, 'load_scripts']); add_action('admin_notices', [$this, 'show_migrate_notice']); add_action('wp_ajax_dhl_legacy_parcel_dismiss_migrate_notice', [$this, 'dismiss_notice']); add_action('wp_ajax_dhl_legacy_parcel_dismiss_migrate_notice_forever', [$this, 'dismiss_notice_forever']); } public function show_migrate_notice() { if (get_site_transient(self::NOTICE_TAG_MIGRATE)) { return; } if ( $this->is_home_screen() || $this->is_ordergrid_screen() || $this->is_order_screen() || $this->is_wc_settings_screen() ) { ?>

', '' ) ?>

'success', 'data' => [], 'message' => null, ], 200 ); } public function dismiss_notice_forever() { check_ajax_referer('pr-dhl-legacy-parcel-dismiss-notice', 'security'); update_option(self::NOTICE_TAG_MIGRATE_FOREVER, true); wp_send_json( [ 'status' => 'success', 'data' => [], 'message' => null, ], 200 ); } protected function check_was_enabled_config() { $shipping_method = get_option('woocommerce_dhlpwc_settings'); if (empty($shipping_method)) { return false; } if (! isset($shipping_method['enable_all'])) { return false; } if ($shipping_method['enable_all'] != 'yes') { return false; } if (empty($shipping_method['user_id'])) { return false; } if (empty($shipping_method['key'])) { return false; } if (empty($shipping_method['account_id'])) { return false; } return true; } protected function check_eligible_country() { $country_code = wc_get_base_location(); if (! in_array( $country_code['country'], [ 'NL', 'BE', 'LU', ] )) { return false; } return true; } protected function is_home_screen() { if (! function_exists('get_current_screen')) { return false; } $screen = get_current_screen(); if (! isset($screen)) { return false; } if ($screen->base !== 'dashboard') { return false; } return true; } protected function is_ordergrid_screen() { if (! function_exists('get_current_screen')) { return false; } $screen = get_current_screen(); if (! isset($screen)) { return false; } if ($screen->base !== 'edit' || $screen->post_type !== 'shop_order') { return false; } return true; } protected function is_order_screen() { if (! function_exists('get_current_screen')) { return false; } $screen = get_current_screen(); if (! isset($screen)) { return false; } if ($screen->base !== 'post' || $screen->post_type !== 'shop_order') { return false; } return true; } protected function is_wc_settings_screen() { if (! function_exists('get_current_screen')) { return false; } $screen = get_current_screen(); if (! isset($screen)) { return false; } if ($screen->base !== 'woocommerce_page_wc-settings') { return false; } return true; } public function load_scripts() { if ( $this->is_home_screen() || $this->is_ordergrid_screen() || $this->is_order_screen() || $this->is_wc_settings_screen() ) { $dismiss_data = [ 'security' => wp_create_nonce('pr-dhl-legacy-parcel-dismiss-notice'), ]; wp_enqueue_script('wc-shipment-dhl-legacy-parcel-dismiss-notice-js', PR_DHL_PLUGIN_DIR_URL.'/assets/js/pr-dhl-notice-legacy-parcel.js', ['jquery'], PR_DHL_VERSION); wp_localize_script('wc-shipment-dhl-legacy-parcel-dismiss-notice-js', 'dhl_legacy_parcel_dismiss_notice', $dismiss_data); } } } }