notices
2 hours ago
table-rate
2 hours ago
tracker
2 hours ago
views
2 hours ago
Flexible_Shipping_Contextual_Info.php
2 hours ago
class-flexible-shipping-plugin.php
2 hours ago
class-flexible-shipping-plugin.php
1008 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin. |
| 4 | * |
| 5 | * @package Flexible Shippign |
| 6 | */ |
| 7 | |
| 8 | use FSVendor\Octolize\Blocks\IntegrationData; |
| 9 | use FSVendor\Octolize\Blocks\Registrator; |
| 10 | use FSVendor\Octolize\Blocks\StoreEndpoint; |
| 11 | use FSVendor\Octolize\Brand\Assets\AdminAssets; |
| 12 | use FSVendor\Octolize\Brand\UpsellingBox\ShippingMethodShouldShowStrategy; |
| 13 | use FSVendor\Octolize\Docs\Chat\DocsChat; |
| 14 | use FSVendor\Octolize\ShippingExtensions\ShippingExtensions; |
| 15 | use FSVendor\Octolize\Tracker\DeactivationTracker\OctolizeReasonsFactory; |
| 16 | use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayAndConditions; |
| 17 | use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayGetParameterValue; |
| 18 | use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayOrConditions; |
| 19 | use FSVendor\Octolize\Tracker\OptInNotice\ShouldDisplayShippingMethodInstanceSettings; |
| 20 | use FSVendor\Octolize\Tracker\TrackerInitializer; |
| 21 | use FSVendor\Psr\Log\LoggerInterface; |
| 22 | use FSVendor\Psr\Log\NullLogger; |
| 23 | use FSVendor\WPDesk\FS\Compatibility\PluginCompatibility; |
| 24 | use FSVendor\WPDesk\ShowDecision\GetStrategy; |
| 25 | use FSVendor\WPDesk\ShowDecision\OrStrategy; |
| 26 | use FSVendor\WPDesk\FS\Shipment\ShipmentFunctionality; |
| 27 | use FSVendor\WPDesk\FS\TableRate\Logger\Assets; |
| 28 | use FSVendor\WPDesk\Logger\SimpleLoggerFactory; |
| 29 | use FSVendor\WPDesk\Mutex\WordpressPostMutex; |
| 30 | use FSVendor\WPDesk\Notice\AjaxHandler; |
| 31 | use FSVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin; |
| 32 | use FSVendor\WPDesk\PluginBuilder\Plugin\Activateable; |
| 33 | use FSVendor\WPDesk\PluginBuilder\Plugin\HookableCollection; |
| 34 | use FSVendor\WPDesk\PluginBuilder\Plugin\HookableParent; |
| 35 | use FSVendor\WPDesk\PluginBuilder\Plugin\TemplateLoad; |
| 36 | use FSVendor\WPDesk\RepositoryRating\DisplayStrategy\ShippingMethodDisplayDecision; |
| 37 | use FSVendor\WPDesk\RepositoryRating\PopupPetition\PopupPetition; |
| 38 | use FSVendor\WPDesk\RepositoryRating\RepositoryRatingPetitionText; |
| 39 | use FSVendor\WPDesk\RepositoryRating\TextPetitionDisplayer; |
| 40 | use FSVendor\WPDesk\Session\SessionFactory; |
| 41 | use FSVendor\WPDesk\ShowDecision\WooCommerce\ShippingMethodInstanceStrategy; |
| 42 | use FSVendor\WPDesk\ShowDecision\WooCommerce\ShippingMethodStrategy; |
| 43 | use FSVendor\WPDesk\View\Resolver\ChainResolver; |
| 44 | use FSVendor\WPDesk\View\Resolver\DirResolver; |
| 45 | use FSVendor\WPDesk\View\Resolver\WPThemeResolver; |
| 46 | use FSVendor\WPDesk\WooCommerce\CurrencySwitchers\FilterConvertersFactory; |
| 47 | use FSVendor\WPDesk\WooCommerce\CurrencySwitchers\ShippingIntegrations; |
| 48 | use WPDesk\FS\Blocks\FreeShipping\FreeShippingBlock; |
| 49 | use WPDesk\FS\Blocks\FreeShipping\FreeShippingStoreEndpointData; |
| 50 | use WPDesk\FS\Admin\MarketplaceSuggestionsRedirect; |
| 51 | use WPDesk\FS\Helpers\FlexibleShippingMethodsChecker; |
| 52 | use WPDesk\FS\Helpers\WooSettingsPageChecker; |
| 53 | use WPDesk\FS\HookProvider\Admin\DocsChatSettingsProvider; |
| 54 | use WPDesk\FS\Integration\ExternalPluginAccess; |
| 55 | use WPDesk\FS\Newsletter\SubscriptionForm; |
| 56 | use WPDesk\FS\Onboarding\TableRate\FinishOption; |
| 57 | use WPDesk\FS\Onboarding\TableRate\Onboarding; |
| 58 | use WPDesk\FS\Onboarding\TableRate\OptionAjaxUpdater; |
| 59 | use WPDesk\FS\Plugin\PluginActivation; |
| 60 | use WPDesk\FS\ProFeatures; |
| 61 | use WPDesk\FS\ProVersion\ProVersionUpdateReminder; |
| 62 | use WPDesk\FS\Shipment; |
| 63 | use WPDesk\FS\TableRate\AI\TrackerDataOnShippingMethodSaver; |
| 64 | use WPDesk\FS\TableRate\ContextualInfo; |
| 65 | use WPDesk\FS\TableRate\Debug\DebugTracker; |
| 66 | use WPDesk\FS\TableRate\Debug\MultipleShippingZonesMatchedSameTerritoryNotice; |
| 67 | use WPDesk\FS\TableRate\Debug\MultipleShippingZonesMatchedSameTerritoryTracker; |
| 68 | use WPDesk\FS\TableRate\Debug\NoShippingMethodsNotice; |
| 69 | use WPDesk\FS\TableRate\FreeShipping\FreeShippingNotice; |
| 70 | use WPDesk\FS\TableRate\FreeShipping\FreeShippingNoticeGenerator; |
| 71 | use WPDesk\FS\TableRate\FreeShipping\FreeShippingNoticeRenderer; |
| 72 | use WPDesk\FS\TableRate\FreeShipping\NoticeTextSettings; |
| 73 | use WPDesk\FS\TableRate\FreeShipping\ProgressBarSettings; |
| 74 | use WPDesk\FS\TableRate\FreeShipping\Tracker\ThresholdAlertTracker; |
| 75 | use WPDesk\FS\TableRate\ImporterExporter\Exporter; |
| 76 | use WPDesk\FS\TableRate\ImporterExporter\ExporterData; |
| 77 | use WPDesk\FS\TableRate\ImporterExporter\ImporterData; |
| 78 | use WPDesk\FS\TableRate\MultiCurrency; |
| 79 | use WPDesk\FS\TableRate\Order\ItemMeta; |
| 80 | use WPDesk\FS\TableRate\Rule\PreconfiguredScenarios; |
| 81 | use WPDesk\FS\TableRate\Rule\TrackerData; |
| 82 | use WPDesk\FS\TableRate\RulesSettingsField; |
| 83 | use WPDesk\FS\TableRate\ShippingMethod\BlockEditing\BlockEditing; |
| 84 | use WPDesk\FS\TableRate\ShippingMethod\Convert\ConvertAction; |
| 85 | use WPDesk\FS\TableRate\ShippingMethod\Convert\ConvertNotice; |
| 86 | use WPDesk\FS\TableRate\ShippingMethod\Convert\ConvertTracker; |
| 87 | use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateAction; |
| 88 | use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateNotice; |
| 89 | use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateScript; |
| 90 | use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateTracker; |
| 91 | use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicatorChecker; |
| 92 | use WPDesk\FS\TableRate\ShippingMethod\Management\ShippingMethodManagement; |
| 93 | use WPDesk\FS\TableRate\ShippingMethod\MethodDescription; |
| 94 | use WPDesk\FS\TableRate\ShippingMethod\MethodLogoCheckoutBlocksAssets; |
| 95 | use WPDesk\FS\TableRate\ShippingMethod\MethodLogoSettingsField; |
| 96 | use WPDesk\FS\TableRate\ShippingMethod\Tracker\MethodLogoTracker; |
| 97 | use WPDesk\FS\TableRate\ShippingMethod\MethodTitle; |
| 98 | use WPDesk\FS\TableRate\ShippingMethodSingle; |
| 99 | use WPDesk\FS\TableRate\ShippingMethodsIntegration\ShippingRate; |
| 100 | use WPDesk\FS\TableRate\Tax\Tracker; |
| 101 | use WPDesk\FS\TableRate\UserFeedback; |
| 102 | use WPDesk\WooCommerceCartWeight\Block\StoreEndpointData; |
| 103 | |
| 104 | /** |
| 105 | * Class Flexible_Shipping_Plugin |
| 106 | */ |
| 107 | class Flexible_Shipping_Plugin extends AbstractPlugin implements HookableCollection, Activateable { |
| 108 | |
| 109 | use HookableParent; |
| 110 | use TemplateLoad; |
| 111 | |
| 112 | /* |
| 113 | * Plugin file |
| 114 | */ |
| 115 | const PLUGIN_FILE = 'flexible-shipping/flexible-shipping.php'; |
| 116 | |
| 117 | const PRIORITY_BEFORE_SHARED_HELPER = -35; |
| 118 | const PRIORITY_LAST = 999999; |
| 119 | const PRIORITY_AFTER_DEFAULT = 20; |
| 120 | const FS_FREE_SHIPPING_NOTICE_NAME = 'fs_free_shipping_notice'; |
| 121 | |
| 122 | /** |
| 123 | * Scripts version. |
| 124 | * |
| 125 | * @var string |
| 126 | */ |
| 127 | private $scripts_version = '2'; |
| 128 | |
| 129 | /** |
| 130 | * Admin notices. |
| 131 | * |
| 132 | * @var WPDesk_Flexible_Shipping_Admin_Notices |
| 133 | */ |
| 134 | public $admin_notices; |
| 135 | |
| 136 | /** |
| 137 | * Default settings tab. |
| 138 | * |
| 139 | * @var string |
| 140 | */ |
| 141 | private $default_settings_tab = 'connect'; |
| 142 | |
| 143 | /** |
| 144 | * Renderer. |
| 145 | * |
| 146 | * @var FSVendor\WPDesk\View\Renderer\Renderer; |
| 147 | */ |
| 148 | private $renderer; |
| 149 | |
| 150 | /** |
| 151 | * Is order processed on checkout? |
| 152 | * |
| 153 | * @var bool |
| 154 | */ |
| 155 | private $is_order_processed_on_checkout = false; |
| 156 | |
| 157 | /** |
| 158 | * Logger. |
| 159 | * |
| 160 | * @var LoggerInterface |
| 161 | */ |
| 162 | private $logger; |
| 163 | |
| 164 | /** |
| 165 | * Flexible_Invoices_Reports_Plugin constructor. |
| 166 | * |
| 167 | * @param FSVendor\WPDesk_Plugin_Info $plugin_info Plugin info. |
| 168 | */ |
| 169 | public function __construct( FSVendor\WPDesk_Plugin_Info $plugin_info ) { |
| 170 | $this->scripts_version = FLEXIBLE_SHIPPING_VERSION . '.' . $this->scripts_version; |
| 171 | $this->plugin_info = $plugin_info; |
| 172 | parent::__construct( $this->plugin_info ); |
| 173 | $this->init_logger(); |
| 174 | $this->init_logger_on_shipment(); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Init logger on WPDesk_Flexible_Shipping_Shipment class. |
| 179 | */ |
| 180 | private function init_logger_on_shipment() { |
| 181 | // WPDesk_Flexible_Shipping_Shipment::set_fs_logger( $this->logger ); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Init logger on WPDesk_Flexible_Shipping class. |
| 186 | * |
| 187 | * @internal |
| 188 | */ |
| 189 | public function init_logger_on_shipping_method() { |
| 190 | WPDesk_Flexible_Shipping::set_fs_logger( $this->logger ); |
| 191 | ShippingMethodSingle::set_fs_logger( $this->logger ); |
| 192 | ShippingRate::set_fs_logger( $this->logger ); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Initialize $this->logger |
| 197 | * |
| 198 | * @return LoggerInterface |
| 199 | */ |
| 200 | private function init_logger() { |
| 201 | $logger_settings = new WPDesk_Flexible_Shipping_Logger_Settings(); |
| 202 | if ( $logger_settings->is_enabled() ) { |
| 203 | add_filter( 'wpdesk_is_wp_log_capture_permitted', '__return_false' ); |
| 204 | |
| 205 | return $this->logger = ( new SimpleLoggerFactory( $logger_settings->get_logger_channel_name() ) )->getLogger(); |
| 206 | } |
| 207 | |
| 208 | return $this->logger = new NullLogger(); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | /** |
| 213 | * Load dependencies. |
| 214 | */ |
| 215 | private function load_dependencies() { |
| 216 | global $wpdb; |
| 217 | |
| 218 | require_once __DIR__ . '/../inc/functions.php'; |
| 219 | |
| 220 | $session_factory = new SessionFactory(); |
| 221 | |
| 222 | $this->add_hookable( new ShipmentFunctionality( $this->logger, trailingslashit( $this->get_plugin_assets_url() ) . '../vendor_prefixed/wpdesk/wp-wpdesk-fs-shipment/assets/', $this->scripts_version ) ); |
| 223 | |
| 224 | $this->add_hookable( new Shipment\FilterOrders() ); |
| 225 | $this->add_hookable( new Shipment\ModifyStatuses() ); |
| 226 | $this->add_hookable( new Shipment\DispatchLabelFile() ); |
| 227 | $this->add_hookable( new Shipment\BulkAction( $session_factory ) ); |
| 228 | $this->add_hookable( new Shipment\AdminNotices( $session_factory ) ); |
| 229 | $this->add_hookable( new Shipment\ModifyOrderTable( $session_factory ) ); |
| 230 | |
| 231 | new WPDesk_Flexible_Shipping_Multilingual( $this ); |
| 232 | |
| 233 | $this->admin_notices = new WPDesk_Flexible_Shipping_Admin_Notices( $this ); |
| 234 | |
| 235 | $this->add_hookable( new WPDesk\FS\Rate\WPDesk_Flexible_Shipping_Rate_Notice() ); |
| 236 | |
| 237 | $this->add_hookable( new WPDesk_Flexible_Shipping_Shorcode_Unit_Weight() ); |
| 238 | $this->add_hookable( new WPDesk_Flexible_Shipping_Shorcode_Unit_Dimension() ); |
| 239 | |
| 240 | $this->add_hookable( new AjaxHandler( trailingslashit( $this->get_plugin()->get_plugin_url() ) . 'vendor_prefixed/wpdesk/wp-notice/assets' ) ); |
| 241 | |
| 242 | $this->add_hookable( new WPDesk_Flexible_Shipping_Method_Created_Tracker_Deactivation_Data() ); |
| 243 | |
| 244 | $this->add_hookable( new ShippingIntegrations( 'flexible_shipping' ) ); |
| 245 | |
| 246 | $this->add_hookable( new WPDesk_Flexible_Shipping_Order_Item_Meta() ); |
| 247 | |
| 248 | $this->add_hookable( new Assets( trailingslashit( $this->get_plugin_url() ) . 'vendor_prefixed/wpdesk/wp-wpdesk-fs-table-rate/assets', $this->scripts_version ) ); |
| 249 | |
| 250 | $this->add_hookable( new NoShippingMethodsNotice( |
| 251 | current_user_can( 'manage_woocommerce' ) && 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' ) |
| 252 | ) ); |
| 253 | |
| 254 | $this->add_hookable( new DebugTracker() ); |
| 255 | |
| 256 | $this->add_hookable( new PluginCompatibility() ); |
| 257 | |
| 258 | $this->add_hookable( new UserFeedback() ); |
| 259 | |
| 260 | //Onboarding |
| 261 | $setting_page_checker = new WooSettingsPageChecker(); |
| 262 | $fs_methods_checker = new FlexibleShippingMethodsChecker(); |
| 263 | |
| 264 | $finish_option = new FinishOption(); |
| 265 | $this->add_hookable( new OptionAjaxUpdater( $finish_option ) ); |
| 266 | $this->add_hookable( new Onboarding( |
| 267 | $finish_option, |
| 268 | $this->scripts_version, |
| 269 | trailingslashit( $this->get_plugin_assets_url() ), |
| 270 | $setting_page_checker, |
| 271 | $fs_methods_checker |
| 272 | ) |
| 273 | ); |
| 274 | $this->add_hookable( new \WPDesk\FS\Onboarding\TableRate\Tracker( $finish_option ) ); |
| 275 | |
| 276 | $this->add_hookable( new ShippingExtensions( $this->plugin_info ) ); |
| 277 | |
| 278 | $this->add_hookable( new MethodTitle() ); |
| 279 | $this->add_hookable( new MethodDescription( $this->renderer ) ); |
| 280 | $this->add_hookable( new MethodLogoCheckoutBlocksAssets( $this->get_plugin_url(), $this->scripts_version ) ); |
| 281 | $this->add_hookable( new MethodLogoSettingsField() ); |
| 282 | $this->add_hookable( new MethodLogoTracker() ); |
| 283 | |
| 284 | $this->add_hookable( new Exporter() ); |
| 285 | $this->add_hookable( new ImporterData() ); |
| 286 | $this->add_hookable( new ExporterData() ); |
| 287 | |
| 288 | $shipping_method_management = new ShippingMethodManagement( $wpdb ); |
| 289 | |
| 290 | // Converter. |
| 291 | $this->add_hookable( new ConvertAction( $shipping_method_management ) ); |
| 292 | $this->add_hookable( new ConvertNotice() ); |
| 293 | $this->add_hookable( new ConvertTracker() ); |
| 294 | |
| 295 | // Duplicate FS Method. |
| 296 | $duplicator_checker = new DuplicatorChecker( $shipping_method_management ); |
| 297 | $this->add_hookable( new DuplicateAction( $duplicator_checker, $shipping_method_management ) ); |
| 298 | $this->add_hookable( new DuplicateNotice() ); |
| 299 | $this->add_hookable( new DuplicateTracker() ); |
| 300 | $this->add_hookable( new DuplicateScript( |
| 301 | trailingslashit( $this->get_plugin_assets_url() ), |
| 302 | $this->scripts_version |
| 303 | ) |
| 304 | ); |
| 305 | |
| 306 | // Block Settings. |
| 307 | $this->add_hookable( new BlockEditing() ); |
| 308 | |
| 309 | $this->add_hookable( new ItemMeta() ); |
| 310 | |
| 311 | $this->add_hookable( new PreconfiguredScenarios\Tracker\AjaxTracker() ); |
| 312 | $this->add_hookable( new PreconfiguredScenarios\Tracker\Tracker() ); |
| 313 | |
| 314 | // Pro Features. |
| 315 | $tracking_data = new ProFeatures\Tracker\TrackingData(); |
| 316 | $this->add_hookable( new ProFeatures\Tracker\AjaxTracker( $tracking_data ) ); |
| 317 | $this->add_hookable( new ProFeatures\Tracker\Tracker( $tracking_data ) ); |
| 318 | |
| 319 | // Time tracking |
| 320 | $this->add_hookable( new \WPDesk\FS\TableRate\ShippingMethod\Timestamps\MethodTimestamps() ); |
| 321 | $this->add_hookable( new \WPDesk\FS\TableRate\ShippingMethod\Timestamps\TrackerData() ); |
| 322 | |
| 323 | $this->add_hookable( new PluginActivation() ); |
| 324 | |
| 325 | $this->add_hookable( new MultipleShippingZonesMatchedSameTerritoryTracker() ); |
| 326 | |
| 327 | $this->add_hookable( new Tracker() ); |
| 328 | |
| 329 | $this->add_hookable( new ProVersionUpdateReminder( 'pl_PL' === get_locale() ) ); |
| 330 | |
| 331 | $this->add_hookable( new \WPDesk\FS\Plugin\PluginLinks( $this->get_plugin_file_path() ) ); |
| 332 | |
| 333 | $brand_assets_url = $this->get_plugin_assets_url() . '../vendor_prefixed/octolize/wp-octolize-brand-assets/assets/'; |
| 334 | |
| 335 | $this->add_hookable( new \WPDesk\FS\AdvertMetabox\ProPluginAdvertMetabox( $brand_assets_url ) ); |
| 336 | $this->add_hookable( new \WPDesk\FS\AdvertMetabox\FsiePluginAdvertMetabox( $brand_assets_url ) ); |
| 337 | |
| 338 | $should_show_strategy = new ShippingMethodShouldShowStrategy( \WPDesk_Flexible_Shipping_Settings::METHOD_ID ); |
| 339 | $this->add_hookable( new AdminAssets( $brand_assets_url, 'fs', $should_show_strategy ) ); |
| 340 | |
| 341 | // Shipping methods integration. |
| 342 | $this->add_hookable( new \WPDesk\FS\TableRate\ShippingMethodsIntegration\Integration() ); |
| 343 | |
| 344 | // Upgrade onboarding |
| 345 | $this->add_hookable( new WPDesk\FS\Plugin\UpgradeOnboarding( $this->plugin_info ) ); |
| 346 | |
| 347 | // CSAT |
| 348 | $this->add_hookable( |
| 349 | new FSVendor\Octolize\Csat\Csat( |
| 350 | new \WPDesk\FS\Csat\CsatOptionDependedOnShippingMethodAndAiUsage( 'csat_flexible_shipping_ai', 'flexible_shipping_single' ), |
| 351 | new \FSVendor\Octolize\Csat\CsatCodeFromFile( __DIR__ . '/views/csat.php' ), |
| 352 | 'woocommerce_after_settings_shipping', |
| 353 | new ShippingMethodInstanceStrategy( new \WC_Shipping_Zones(), 'flexible_shipping_single' ) |
| 354 | ) |
| 355 | ); |
| 356 | |
| 357 | // Newsletter |
| 358 | $this->add_hookable( new SubscriptionForm() ); |
| 359 | |
| 360 | // Redirect woo marketplace suggestions |
| 361 | $this->add_hookable( new MarketplaceSuggestionsRedirect( $this->prepare_marketplace_suggestions_should_show_strategy() ) ); |
| 362 | |
| 363 | $this->initialize_docs_chat(); |
| 364 | |
| 365 | // Rating petition |
| 366 | add_action( 'admin_init', [ $this, 'init_rating_petition' ] ); |
| 367 | } |
| 368 | |
| 369 | public function init_rating_petition() { |
| 370 | if ( class_exists( '\WC_Shipping_Zones' ) ) { |
| 371 | $shipping_method_display_decision = new ShippingMethodDisplayDecision( new \WC_Shipping_Zones(), ShippingMethodSingle::SHIPPING_METHOD_ID ); |
| 372 | ( new TextPetitionDisplayer( |
| 373 | 'woocommerce_after_settings_shipping', |
| 374 | $shipping_method_display_decision, |
| 375 | new RepositoryRatingPetitionText( |
| 376 | 'Octolize', |
| 377 | $this->plugin_info->get_plugin_name(), |
| 378 | 'https://octol.io/fs-rate', |
| 379 | 'center' |
| 380 | ) |
| 381 | ) )->hooks(); |
| 382 | |
| 383 | $option_name = 'flexible-shipping-method-update-count'; |
| 384 | $max_update_count = 5; |
| 385 | $option_value = (int) get_option( $option_name, 0 ); |
| 386 | if ( $option_value >= $max_update_count ) { |
| 387 | $current_user = wp_get_current_user(); |
| 388 | ( new PopupPetition( |
| 389 | 'flexible-shipping', |
| 390 | __( 'Flexible Shipping', 'flexible-shipping' ), |
| 391 | 'help@octolize.com', |
| 392 | $current_user ? $current_user->user_email : '', |
| 393 | 'admin_footer', |
| 394 | $shipping_method_display_decision |
| 395 | ) )->init()->hooks(); |
| 396 | } |
| 397 | |
| 398 | add_action( 'flexible_shipping_method_updated', function ( $instance_id ) use ( $option_name, $max_update_count, $option_value ) { |
| 399 | if ( $option_value < $max_update_count ) { |
| 400 | update_option( $option_name, (int) get_option( $option_name, 0 ) + 1 ); |
| 401 | } |
| 402 | } ); |
| 403 | |
| 404 | add_action( 'wpdesk_rating_petition_postpone', function ( $plugin_slug ) use ( $option_name, $max_update_count ) { |
| 405 | if ( $plugin_slug === 'flexible-shipping' ) { |
| 406 | update_option( $option_name, (int) floor( $max_update_count / 2 ) ); |
| 407 | } |
| 408 | } ); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Init contextual info on Flexible Shipping settings fields. |
| 414 | * |
| 415 | * @internal |
| 416 | */ |
| 417 | public function init_contextual_info() { |
| 418 | $base_location = wc_get_base_location(); |
| 419 | $base_country = $base_location['country']; |
| 420 | $contextual_info_creator = new ContextualInfo\Creator( $base_country ); |
| 421 | $contextual_info_creator->create_contextual_info(); |
| 422 | $contextual_info_creator->hooks(); |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * Init base variables for plugin |
| 427 | */ |
| 428 | public function init_base_variables() { |
| 429 | $this->plugin_url = $this->plugin_info->get_plugin_url(); |
| 430 | |
| 431 | $this->plugin_path = $this->plugin_info->get_plugin_dir(); |
| 432 | $this->template_path = $this->plugin_info->get_text_domain(); |
| 433 | |
| 434 | $this->plugin_namespace = $this->plugin_info->get_text_domain(); |
| 435 | $this->template_path = $this->plugin_info->get_text_domain(); |
| 436 | $this->default_settings_tab = 'main'; |
| 437 | |
| 438 | $this->settings_url = admin_url( 'admin.php?page=flexible-shipping-settings' ); |
| 439 | $this->docs_url = get_locale() === 'pl_PL' ? 'https://octol.io/fs-docs-pl' : 'https://octol.io/fs-docs'; |
| 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Set renderer. |
| 444 | */ |
| 445 | private function init_renderer() { |
| 446 | $resolver = new ChainResolver(); |
| 447 | $resolver->appendResolver( new WPThemeResolver( $this->get_template_path() ) ); |
| 448 | $resolver->appendResolver( new DirResolver( trailingslashit( $this->plugin_path ) . 'templates' ) ); |
| 449 | $this->renderer = new FSVendor\WPDesk\View\Renderer\SimplePhpRenderer( $resolver ); |
| 450 | } |
| 451 | |
| 452 | /** |
| 453 | * Init. |
| 454 | */ |
| 455 | public function init() { |
| 456 | $this->init_base_variables(); |
| 457 | $this->init_renderer(); |
| 458 | $this->load_dependencies(); |
| 459 | $this->init_tracker(); |
| 460 | $this->init_ai(); |
| 461 | $this->hooks(); |
| 462 | $this->init_assets_url_on_rules_settings_field(); |
| 463 | $this->init_checkout_blocks(); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * register_activation_hook handler. |
| 468 | * |
| 469 | * @internal |
| 470 | */ |
| 471 | public function activate() { |
| 472 | ( new PluginActivation() )->add_activation_option_if_not_present(); |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * Hooks. |
| 477 | */ |
| 478 | public function hooks() { |
| 479 | parent::hooks(); |
| 480 | |
| 481 | add_filter( 'woocommerce_shipping_methods', [ |
| 482 | $this, |
| 483 | 'woocommerce_shipping_methods_filter', |
| 484 | ], self::PRIORITY_AFTER_DEFAULT ); |
| 485 | |
| 486 | add_filter( |
| 487 | 'flexible_shipping_method_rate_id', |
| 488 | [ |
| 489 | $this, |
| 490 | 'flexible_shipping_method_rate_id', |
| 491 | ], |
| 492 | 9999999, |
| 493 | 2 |
| 494 | ); |
| 495 | |
| 496 | add_filter( |
| 497 | 'woocommerce_shipping_chosen_method', |
| 498 | [ |
| 499 | $this, |
| 500 | 'woocommerce_default_shipment_method', |
| 501 | ], |
| 502 | 10, |
| 503 | 3 |
| 504 | ); |
| 505 | |
| 506 | add_action( |
| 507 | 'woocommerce_checkout_create_order', |
| 508 | [ |
| 509 | $this, |
| 510 | 'add_flexible_shipping_order_meta_on_checkout', |
| 511 | ] |
| 512 | ); |
| 513 | |
| 514 | add_filter( 'option_woocommerce_cod_settings', [ $this, 'option_woocommerce_cod_settings' ] ); |
| 515 | |
| 516 | add_action( 'woocommerce_init', [ $this, 'init_free_shipping_notice' ] ); |
| 517 | |
| 518 | add_action( 'woocommerce_init', [ $this, 'init_logger_on_shipping_method' ] ); |
| 519 | |
| 520 | add_action( 'woocommerce_init', [ $this, 'init_contextual_info' ] ); |
| 521 | |
| 522 | add_action( 'woocommerce_init', [ $this, 'init_shipping_zones_notice' ] ); |
| 523 | |
| 524 | add_action( 'woocommerce_init', [ $this, 'init_multicurrency' ] ); |
| 525 | |
| 526 | add_action( 'woocommerce_init', [ $this, 'init_external_plugin_access' ] ); |
| 527 | |
| 528 | $this->hooks_on_hookable_objects(); |
| 529 | } |
| 530 | |
| 531 | private function init_checkout_blocks() { |
| 532 | ( new FreeShippingBlock( [ self::FS_FREE_SHIPPING_NOTICE_NAME ] ) )->hooks(); |
| 533 | |
| 534 | $integration_data = ( new IntegrationData() ) |
| 535 | ->set_integration_name( $this->plugin_namespace . '-free-shipping-notice-block-integration' ) |
| 536 | ->set_script_name( '' ) |
| 537 | ->set_script_path( '/assets/blocks/free-shipping-notice-block-integration/' ); |
| 538 | ( new StoreEndpoint( $integration_data->get_integration_name(), 'page_type', false ) )->hooks(); |
| 539 | ( new FreeShippingStoreEndpointData( $integration_data->get_integration_name() ) )->hooks(); |
| 540 | ( new Registrator( |
| 541 | $integration_data, |
| 542 | $this->plugin_path, |
| 543 | $this->get_plugin_file_path(), |
| 544 | false, |
| 545 | false |
| 546 | ) )->hooks(); |
| 547 | |
| 548 | } |
| 549 | |
| 550 | |
| 551 | /** |
| 552 | * . |
| 553 | */ |
| 554 | public function init_multicurrency() { |
| 555 | $prefix = $this->plugin_info->get_plugin_dir(); |
| 556 | ( new FilterConvertersFactory( $prefix ) )->hooks(); |
| 557 | ( new MultiCurrency( $this->logger, $prefix ) )->hooks(); |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * . |
| 562 | */ |
| 563 | public function init_external_plugin_access() { |
| 564 | do_action( 'flexible-shipping/core/initialized', new ExternalPluginAccess( $this->plugin_info->get_version(), $this->logger ) ); |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * . |
| 569 | * @internal |
| 570 | */ |
| 571 | public function init_shipping_zones_notice() { |
| 572 | ( new MultipleShippingZonesMatchedSameTerritoryNotice( WC()->countries, new WC_Shipping_Zones() ) )->hooks(); |
| 573 | } |
| 574 | |
| 575 | /** |
| 576 | * |
| 577 | */ |
| 578 | private function init_assets_url_on_rules_settings_field() { |
| 579 | RulesSettingsField::set_assets_url( untrailingslashit( $this->get_plugin_assets_url() ) ); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * Init free shipping notice. |
| 584 | * |
| 585 | * @internal |
| 586 | */ |
| 587 | public function init_free_shipping_notice() { |
| 588 | $cart = WC()->cart; |
| 589 | $session = WC()->session; |
| 590 | ( new FreeShippingNoticeGenerator( null, null, self::FS_FREE_SHIPPING_NOTICE_NAME ) )->hooks(); |
| 591 | ( new FreeShippingNoticeRenderer( $this->renderer ) )->hooks(); |
| 592 | if ( $cart instanceof WC_Cart && $session instanceof WC_Session ) { |
| 593 | ( new FreeShippingNotice( $cart, $session, self::FS_FREE_SHIPPING_NOTICE_NAME ) )->hooks(); |
| 594 | ( new \WPDesk\FS\TableRate\FreeShipping\Assets( $this->get_plugin_assets_url(), $this->scripts_version ) )->hooks(); |
| 595 | } |
| 596 | ( new NoticeTextSettings() )->hooks(); |
| 597 | ( new ProgressBarSettings() )->hooks(); |
| 598 | ( new \WPDesk\FS\TableRate\FreeShipping\Tracker() )->hooks(); |
| 599 | ( new ThresholdAlertTracker() )->hooks(); |
| 600 | } |
| 601 | |
| 602 | /** |
| 603 | * Init tracker. |
| 604 | */ |
| 605 | private function init_tracker() { |
| 606 | add_action( 'woocommerce_init', function () { |
| 607 | TrackerInitializer::create_from_plugin_info( |
| 608 | $this->plugin_info, |
| 609 | $this->prepare_shoud_display_for_flexible_shipping(), |
| 610 | new OctolizeReasonsFactory( |
| 611 | 'https://octol.io/fs-docs-exit-pop-up', |
| 612 | 'https://octol.io/fs-support-forum-exit-pop-up', |
| 613 | __( 'Flexible Shipping PRO', 'flexible-shipping' ), |
| 614 | 'https://octol.io/fs-contact-exit-pop-up', |
| 615 | ) |
| 616 | )->hooks(); |
| 617 | ( new WPDesk_Flexible_Shipping_Tracker() )->hooks(); |
| 618 | ( new TrackerData() )->hooks(); |
| 619 | } ); |
| 620 | |
| 621 | } |
| 622 | |
| 623 | private function init_ai() { |
| 624 | ( new TrackerDataOnShippingMethodSaver() )->hooks(); |
| 625 | ( new \WPDesk\FS\TableRate\AI\TrackerData() )->hooks(); |
| 626 | } |
| 627 | |
| 628 | /** |
| 629 | * @return ShouldDisplayOrConditions |
| 630 | */ |
| 631 | private function prepare_shoud_display_for_flexible_shipping() { |
| 632 | $should_display = new ShouldDisplayOrConditions(); |
| 633 | $should_display->add_should_diaplay_condition( new ShouldDisplayShippingMethodInstanceSettings( ShippingMethodSingle::SHIPPING_METHOD_ID ) ); |
| 634 | $should_display_and_conditions = new ShouldDisplayAndConditions(); |
| 635 | $should_display_and_conditions->add_should_diaplay_condition( |
| 636 | new ShouldDisplayGetParameterValue( 'page', 'wc-settings' ) |
| 637 | ); |
| 638 | $should_display_and_conditions->add_should_diaplay_condition( |
| 639 | new ShouldDisplayGetParameterValue( 'tab', 'shipping' ) |
| 640 | ); |
| 641 | $should_display_and_conditions->add_should_diaplay_condition( |
| 642 | new ShouldDisplayGetParameterValue( 'section', WPDesk_Flexible_Shipping_Settings::METHOD_ID ) |
| 643 | ); |
| 644 | $should_display->add_should_diaplay_condition( $should_display_and_conditions ); |
| 645 | |
| 646 | return $should_display; |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * @return OrStrategy |
| 651 | */ |
| 652 | private function prepare_marketplace_suggestions_should_show_strategy() { |
| 653 | $show_strategy = new OrStrategy( |
| 654 | new GetStrategy( |
| 655 | [ |
| 656 | [ |
| 657 | 'page' => 'wc-settings', |
| 658 | 'tab' => 'shipping', |
| 659 | 'section' => WPDesk_Flexible_Shipping_Settings::METHOD_ID, |
| 660 | ], |
| 661 | ] |
| 662 | ) |
| 663 | ); |
| 664 | |
| 665 | if ( class_exists( '\WC_Shipping_Zones' ) ) { |
| 666 | $shipping_zones = new \WC_Shipping_Zones(); |
| 667 | $show_strategy->addCondition( new ShippingMethodInstanceStrategy( $shipping_zones, WPDesk_Flexible_Shipping::METHOD_ID ) ); |
| 668 | $show_strategy->addCondition( new ShippingMethodInstanceStrategy( $shipping_zones, ShippingMethodSingle::SHIPPING_METHOD_ID ) ); |
| 669 | } |
| 670 | |
| 671 | return $show_strategy; |
| 672 | } |
| 673 | |
| 674 | private function initialize_docs_chat(): void { |
| 675 | $plugin_slug = 'flexible-shipping'; |
| 676 | $plugin_name = 'Flexible Shipping'; |
| 677 | if ( defined( 'FLEXIBLE_SHIPPING_PRO_VERSION' ) ) { |
| 678 | $plugin_slug = 'flexible-shipping-pro'; |
| 679 | $plugin_name = 'Flexible Shipping PRO'; |
| 680 | } |
| 681 | |
| 682 | $this->add_hookable( |
| 683 | new DocsChat( |
| 684 | $plugin_slug, |
| 685 | $this->get_plugin_url(), |
| 686 | $this->plugin_info->get_version(), |
| 687 | $this->prepare_docs_chat_should_show_strategy(), |
| 688 | new DocsChatSettingsProvider( $plugin_name ) |
| 689 | ) |
| 690 | ); |
| 691 | } |
| 692 | |
| 693 | private function prepare_docs_chat_should_show_strategy(): OrStrategy { |
| 694 | $show_strategy = new OrStrategy( |
| 695 | new ShippingMethodStrategy( \WPDesk_Flexible_Shipping_Settings::METHOD_ID ) |
| 696 | ); |
| 697 | $show_strategy->addCondition( |
| 698 | new ShippingMethodInstanceStrategy( |
| 699 | new \WC_Shipping_Zones(), |
| 700 | ShippingMethodSingle::SHIPPING_METHOD_ID |
| 701 | ) |
| 702 | ); |
| 703 | |
| 704 | return $show_strategy; |
| 705 | } |
| 706 | |
| 707 | /** |
| 708 | * Woocommerce shipping methods filter. |
| 709 | * |
| 710 | * @param array $methods . |
| 711 | * |
| 712 | * @return array |
| 713 | */ |
| 714 | public function woocommerce_shipping_methods_filter( $methods ) { |
| 715 | $methods[ ShippingMethodSingle::SHIPPING_METHOD_ID ] = ShippingMethodSingle::class; |
| 716 | $methods[ WPDesk_Flexible_Shipping::METHOD_ID ] = WPDesk_Flexible_Shipping::class; |
| 717 | |
| 718 | if ( $this->can_register_fs_info() ) { |
| 719 | $methods[ WPDesk_Flexible_Shipping_Settings::METHOD_ID ] = WPDesk_Flexible_Shipping_Settings::class; |
| 720 | } |
| 721 | |
| 722 | return $methods; |
| 723 | } |
| 724 | |
| 725 | /** |
| 726 | * @return bool |
| 727 | */ |
| 728 | private function can_register_fs_info() { |
| 729 | if ( ! is_admin() ) { |
| 730 | return false; |
| 731 | } |
| 732 | |
| 733 | return ! $this->is_adding_order_page() && ! $this->is_editing_order_page(); |
| 734 | } |
| 735 | |
| 736 | /** |
| 737 | * @return bool |
| 738 | */ |
| 739 | private function is_editing_order_page() { |
| 740 | $post = filter_input( INPUT_GET, 'post' ); |
| 741 | $action = filter_input( INPUT_GET, 'action' ); |
| 742 | |
| 743 | return 'edit' === $action && $post; |
| 744 | } |
| 745 | |
| 746 | /** |
| 747 | * @return bool |
| 748 | */ |
| 749 | private function is_adding_order_page() { |
| 750 | $action = filter_input( INPUT_POST, 'action' ); |
| 751 | |
| 752 | return wp_doing_ajax() && 'woocommerce_add_order_shipping' === $action; |
| 753 | } |
| 754 | |
| 755 | /** |
| 756 | * Option woocommerce cod settings filter. |
| 757 | * |
| 758 | * @param array $value . |
| 759 | * |
| 760 | * @return array |
| 761 | */ |
| 762 | public function option_woocommerce_cod_settings( $value ) { |
| 763 | if ( is_checkout() ) { |
| 764 | if ( |
| 765 | ! empty( $value ) |
| 766 | && is_array( $value ) |
| 767 | && 'yes' === $value['enabled'] |
| 768 | && ! empty( $value['enable_for_methods'] ) |
| 769 | && is_array( $value['enable_for_methods'] ) |
| 770 | ) { |
| 771 | foreach ( $value['enable_for_methods'] as $method ) { |
| 772 | if ( 'flexible_shipping' === $method ) { |
| 773 | $all_fs_methods = flexible_shipping_get_all_shipping_methods(); |
| 774 | $all_shipping_methods = flexible_shipping_get_all_shipping_methods(); |
| 775 | $flexible_shipping = $all_shipping_methods['flexible_shipping']; |
| 776 | $flexible_shipping_rates = $flexible_shipping->get_all_rates(); |
| 777 | foreach ( $flexible_shipping_rates as $flexible_shipping_rate ) { |
| 778 | $value['enable_for_methods'][] = $flexible_shipping_rate['id_for_shipping']; |
| 779 | } |
| 780 | break; |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | |
| 786 | return $value; |
| 787 | } |
| 788 | |
| 789 | /** |
| 790 | * Add flexible shipping order meta on checkout. |
| 791 | * |
| 792 | * @param WC_Order $order Order. |
| 793 | */ |
| 794 | public function add_flexible_shipping_order_meta_on_checkout( $order ) { |
| 795 | if ( ! $this->is_order_processed_on_checkout ) { |
| 796 | $mutex = WordpressPostMutex::fromOrder( $order ); |
| 797 | $mutex->acquireLock(); |
| 798 | $this->is_order_processed_on_checkout = true; |
| 799 | $order_shipping_methods = $order->get_shipping_methods(); |
| 800 | foreach ( $order_shipping_methods as $shipping_id => $shipping_method ) { |
| 801 | if ( isset( $shipping_method['item_meta'] ) |
| 802 | && isset( $shipping_method['item_meta']['_fs_method'] ) |
| 803 | ) { |
| 804 | $fs_method = $shipping_method['item_meta']['_fs_method']; |
| 805 | if ( ! empty( $fs_method['method_integration'] ) ) { |
| 806 | $order_meta = $order->get_meta( '_flexible_shipping_integration', false ); |
| 807 | if ( ! in_array( $fs_method['method_integration'], $order_meta, true ) ) { |
| 808 | $order->add_meta_data( '_flexible_shipping_integration', $fs_method['method_integration'] ); |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | $mutex->releaseLock(); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Set appropriate default FS method if no method chosen. |
| 819 | * |
| 820 | * @param string $default Default shipping method in frontend. |
| 821 | * @param WC_Shipping_Rate[] $available_methods Available methods in frontend. |
| 822 | * Function is assigned to woocommerce_default_shipment_method filter. |
| 823 | * In this parameter we expecting array of WC_Shipping_Rate objects. |
| 824 | * But third party plugins can change this parameter type or set it to |
| 825 | * null. |
| 826 | * @param string|bool|null $chosen_method If false or null then no method is chosen. |
| 827 | * |
| 828 | * @return string |
| 829 | */ |
| 830 | public function woocommerce_default_shipment_method( $default, $available_methods, $chosen_method ) { |
| 831 | if ( ! is_array( $available_methods ) ) { |
| 832 | return $default; |
| 833 | } |
| 834 | if ( null === $chosen_method || false === $chosen_method ) { |
| 835 | foreach ( $available_methods as $available_method ) { |
| 836 | $method_meta = $available_method->get_meta_data(); |
| 837 | if ( $method_meta && isset( $method_meta[ WPDesk_Flexible_Shipping::META_DEFAULT ] ) && 'yes' === $method_meta[ WPDesk_Flexible_Shipping::META_DEFAULT ] ) { |
| 838 | $candidate_id = $available_method->get_id(); |
| 839 | if ( array_key_exists( $candidate_id, $available_methods ) ) { |
| 840 | return $candidate_id; |
| 841 | } |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | return $default; |
| 847 | } |
| 848 | |
| 849 | /** |
| 850 | * @param string $suffix . |
| 851 | */ |
| 852 | private function enqueue_rules_scripts( $suffix ) { |
| 853 | wp_register_script( |
| 854 | 'fs_rules_settings', |
| 855 | trailingslashit( $this->get_plugin_assets_url() ) . 'js/rules-settings.js', |
| 856 | [ 'wp-i18n' ], |
| 857 | $this->scripts_version |
| 858 | ); |
| 859 | wp_enqueue_script( 'fs_rules_settings' ); |
| 860 | wp_enqueue_style( |
| 861 | 'fs_rules_settings', |
| 862 | trailingslashit( $this->get_plugin_assets_url() ) . 'css/rules-settings.css', |
| 863 | [], |
| 864 | $this->scripts_version |
| 865 | ); |
| 866 | wp_set_script_translations( 'fs_rules_settings', 'flexible-shipping', $this->plugin_path . '/lang/' ); |
| 867 | |
| 868 | } |
| 869 | |
| 870 | /** |
| 871 | * Admin enqueue scripts. |
| 872 | */ |
| 873 | public function admin_enqueue_scripts() { |
| 874 | if ( $this->should_enqueue_admin_scripts() ) { |
| 875 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 876 | wp_register_script( |
| 877 | 'fs_admin', |
| 878 | trailingslashit( $this->get_plugin_assets_url() ) . 'js/admin' . $suffix . '.js', |
| 879 | [ 'jquery' ], |
| 880 | $this->scripts_version |
| 881 | ); |
| 882 | |
| 883 | $notice_url = get_locale() == 'pl_PL' ? 'https://octol.io/fs-rate-not-good-pl' : 'https://octol.io/fs-rate-not-good'; |
| 884 | wp_localize_script( |
| 885 | 'fs_admin', |
| 886 | 'fs_admin', |
| 887 | [ |
| 888 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 889 | 'notice_not_good_enought' => sprintf( |
| 890 | // Translators: link. |
| 891 | __( 'How can We make Flexible Shipping better for you? %1$sJust write to us.%2$s', 'flexible-shipping' ), |
| 892 | '<a class="button close-fs-rate-notice" target="_blank" href="' . esc_url( $notice_url ) . '">', |
| 893 | '</a>' |
| 894 | ), |
| 895 | ] |
| 896 | ); |
| 897 | wp_enqueue_script( 'fs_admin' ); |
| 898 | |
| 899 | $current_screen = get_current_screen(); |
| 900 | |
| 901 | wp_register_script( |
| 902 | 'wpdesk_contextual_info', |
| 903 | trailingslashit( $this->get_plugin_assets_url() ) . 'js/contextual-info' . $suffix . '.js', |
| 904 | [ 'jquery' ], |
| 905 | $this->scripts_version |
| 906 | ); |
| 907 | wp_enqueue_script( 'wpdesk_contextual_info' ); |
| 908 | |
| 909 | if ( ! empty( $current_screen ) && 'shop_order' === $current_screen->id ) { |
| 910 | wp_enqueue_media(); |
| 911 | } |
| 912 | |
| 913 | wp_enqueue_style( |
| 914 | 'fs_admin', |
| 915 | trailingslashit( $this->get_plugin_assets_url() ) . 'css/admin.css', |
| 916 | [], |
| 917 | $this->scripts_version |
| 918 | ); |
| 919 | wp_enqueue_style( |
| 920 | 'fs_font', |
| 921 | trailingslashit( $this->get_plugin_assets_url() ) . 'css/font' . $suffix . '.css', |
| 922 | [], |
| 923 | $this->scripts_version |
| 924 | ); |
| 925 | |
| 926 | $this->enqueue_rules_scripts( $suffix ); |
| 927 | |
| 928 | do_action( 'flexible-shipping/admin/enqueue_scripts', $this, $suffix ); |
| 929 | |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * Should enqueue admin scripts? |
| 935 | */ |
| 936 | private function should_enqueue_admin_scripts() { |
| 937 | $current_screen = get_current_screen(); |
| 938 | |
| 939 | if ( ! $current_screen ) { |
| 940 | return false; |
| 941 | } |
| 942 | |
| 943 | $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) ); |
| 944 | |
| 945 | if ( |
| 946 | 'woocommerce_page_wc-orders' === $current_screen->id |
| 947 | || in_array( $current_screen->post_type, [ 'shop_order', 'shop_subscription', ], true ) |
| 948 | || $wc_screen_id . '_page_wc-settings' === $current_screen->id |
| 949 | || 'woocommerce_page_wc-settings' === $current_screen->id ) { |
| 950 | return true; |
| 951 | } |
| 952 | |
| 953 | return false; |
| 954 | } |
| 955 | |
| 956 | /** |
| 957 | * Enqueue Wordpress scripts. |
| 958 | */ |
| 959 | public function wp_enqueue_scripts() { |
| 960 | $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
| 961 | } |
| 962 | |
| 963 | /** |
| 964 | * Links filter. |
| 965 | * |
| 966 | * @param array $links . |
| 967 | * |
| 968 | * @return array |
| 969 | */ |
| 970 | public function links_filter( $links ) { |
| 971 | $settings_url = admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=' . \WPDesk_Flexible_Shipping_Settings::METHOD_ID ); |
| 972 | |
| 973 | $plugin_links = [ |
| 974 | '<a href="' . $settings_url . '">' . __( |
| 975 | 'Settings', |
| 976 | 'flexible-shipping' |
| 977 | ) . '</a>', |
| 978 | ]; |
| 979 | |
| 980 | if ( ! defined( 'FLEXIBLE_SHIPPING_PRO_VERSION' ) ) { |
| 981 | $pro_link = get_locale() === 'pl_PL' ? 'https://octol.io/fs-upgrade-pl' : 'https://octol.io/fs-upgrade'; |
| 982 | $plugin_links[] = '<a href="' . esc_url( $pro_link ) . '" target="_blank" style="color:#00B62E;font-weight:bold;">' . __( |
| 983 | 'Buy PRO', |
| 984 | 'flexible-shipping' |
| 985 | ) . '</a>'; |
| 986 | } |
| 987 | |
| 988 | return array_merge( $plugin_links, $links ); |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * . |
| 993 | * @param string $method_id . |
| 994 | * @param array $shipping_method . |
| 995 | * |
| 996 | * @return string |
| 997 | */ |
| 998 | public function flexible_shipping_method_rate_id( $method_id, array $shipping_method ) { |
| 999 | if ( isset( $shipping_method['id_for_shipping'] ) && '' !== $shipping_method['id_for_shipping'] ) { |
| 1000 | $method_id = $shipping_method['id_for_shipping']; |
| 1001 | } |
| 1002 | |
| 1003 | return $method_id; |
| 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | } |
| 1008 |