PluginProbe ʕ •ᴥ•ʔ
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping / 6.12.0
Weight Based Shipping Table Rate for WooCommerce – Flexible Shipping v6.12.0
6.12.1 6.12.0 6.11.0 6.10.0 6.9.1 6.9.0 6.8.1 6.8.0 6.7.4 6.7.3 6.7.2 6.7.0 4.21.7 4.22.0 4.22.1 4.23.0 4.23.1 4.23.2 4.23.3 4.24.0 4.24.1 4.24.10 4.24.11 4.24.12 4.24.13 4.24.14 4.24.15 4.24.16 4.24.17 4.24.18 4.24.19 4.24.2 4.24.4 4.24.6 4.24.7 4.24.8 4.24.9 4.25.0 4.25.1 4.25.2 4.25.4 4.25.5 4.25.6 4.25.7 4.25.8 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 4.8.0 4.8.1 4.8.3 4.8.4 4.8.5 4.9.0 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.0.9 5.1.0 5.1.1 5.1.2 5.1.3 5.2.0 5.3.0 5.3.1 5.3.3 5.3.4 5.3.5 6.0.0 6.1.0 6.1.1 6.1.2 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.3.0 trunk 6.4.0 1.4 6.4.1 1.4.1 6.4.2 1.5 6.4.3 1.6 6.4.5 1.6.1 6.5.0 1.6.2 6.5.1 1.7 6.5.2 1.8 6.5.3 1.9 6.5.4 1.9.1 6.5.5 1.9.10 6.5.6 1.9.11 6.5.7 1.9.12 6.5.8 1.9.2 6.6.0 1.9.3 6.6.1 1.9.4 6.6.2 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0 2.0.1 2.1 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.6 3.0.7 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.11.4 3.12.0 3.13.0 3.14.0 3.14.1 3.14.2 3.14.3 3.14.4 3.15.0 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.2.0 3.3.1 3.3.10 3.3.11 3.3.12 3.3.13 3.3.14 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.8.0 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.9 4.0.0 4.0.1 4.0.10 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.11.0 4.11.1 4.11.2 4.11.3 4.11.4 4.11.5 4.11.6 4.11.7 4.11.8 4.11.9 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.14.0 4.14.1 4.14.2 4.15.0 4.16.0 4.16.1 4.16.2 4.17.0 4.18.0 4.18.1 4.18.2 4.18.3 4.18.4 4.18.5 4.18.6 4.19.0 4.19.1 4.2.0 4.20.0 4.20.1 4.20.2 4.20.3 4.21.0 4.21.1 4.21.2 4.21.3 4.21.4 4.21.5
flexible-shipping / classes / class-flexible-shipping-plugin.php
flexible-shipping / classes Last commit date
notices 6 days ago table-rate 6 days ago tracker 6 days ago views 6 days ago Flexible_Shipping_Contextual_Info.php 6 days ago class-flexible-shipping-plugin.php 6 days ago
class-flexible-shipping-plugin.php
1042 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\Info\DashboardTracker;
55 use WPDesk\FS\Info\DashboardTrackingData;
56 use WPDesk\FS\Info\DashboardTrackingReceiver;
57 use WPDesk\FS\Integration\ExternalPluginAccess;
58 use WPDesk\FS\Onboarding\TableRate\FinishOption;
59 use WPDesk\FS\Onboarding\TableRate\Onboarding;
60 use WPDesk\FS\Onboarding\TableRate\OptionAjaxUpdater;
61 use WPDesk\FS\Plugin\PluginActivation;
62 use WPDesk\FS\ProFeatures;
63 use WPDesk\FS\ProVersion\ProVersionUpdateReminder;
64 use WPDesk\FS\Shipment;
65 use WPDesk\FS\TableRate\AI\TrackerDataOnShippingMethodSaver;
66 use WPDesk\FS\TableRate\ContextualInfo;
67 use WPDesk\FS\TableRate\Debug\DebugTracker;
68 use WPDesk\FS\TableRate\Debug\MultipleShippingZonesMatchedSameTerritoryNotice;
69 use WPDesk\FS\TableRate\Debug\MultipleShippingZonesMatchedSameTerritoryTracker;
70 use WPDesk\FS\TableRate\Debug\NoShippingMethodsNotice;
71 use WPDesk\FS\TableRate\FreeShipping\FreeShippingNotice;
72 use WPDesk\FS\TableRate\FreeShipping\FreeShippingNoticeGenerator;
73 use WPDesk\FS\TableRate\FreeShipping\FreeShippingNoticeRenderer;
74 use WPDesk\FS\TableRate\FreeShipping\NoticeTextSettings;
75 use WPDesk\FS\TableRate\FreeShipping\ProgressBarSettings;
76 use WPDesk\FS\TableRate\FreeShipping\Tracker\ThresholdAlertTracker;
77 use WPDesk\FS\TableRate\ImporterExporter\Exporter;
78 use WPDesk\FS\TableRate\ImporterExporter\ExporterData;
79 use WPDesk\FS\TableRate\ImporterExporter\ImporterData;
80 use WPDesk\FS\TableRate\MultiCurrency;
81 use WPDesk\FS\TableRate\Order\ItemMeta;
82 use WPDesk\FS\TableRate\Rule\PreconfiguredScenarios;
83 use WPDesk\FS\TableRate\Rule\TrackerData;
84 use WPDesk\FS\TableRate\RulesSettingsField;
85 use WPDesk\FS\TableRate\ShippingMethod\BlockEditing\BlockEditing;
86 use WPDesk\FS\TableRate\ShippingMethod\Convert\ConvertAction;
87 use WPDesk\FS\TableRate\ShippingMethod\Convert\ConvertNotice;
88 use WPDesk\FS\TableRate\ShippingMethod\Convert\ConvertTracker;
89 use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateAction;
90 use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateNotice;
91 use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateScript;
92 use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicateTracker;
93 use WPDesk\FS\TableRate\ShippingMethod\Duplicate\DuplicatorChecker;
94 use WPDesk\FS\TableRate\ShippingMethod\Management\ShippingMethodManagement;
95 use WPDesk\FS\TableRate\ShippingMethod\MethodDescription;
96 use WPDesk\FS\TableRate\ShippingMethod\MethodLogoCheckoutBlocksAssets;
97 use WPDesk\FS\TableRate\ShippingMethod\MethodLogoSettingsField;
98 use WPDesk\FS\TableRate\ShippingMethod\Tracker\MethodLogoTracker;
99 use WPDesk\FS\TableRate\ShippingMethod\MethodTitle;
100 use WPDesk\FS\TableRate\ShippingMethodSingle;
101 use WPDesk\FS\TableRate\ShippingMethodsIntegration\ShippingRate;
102 use WPDesk\FS\TableRate\Tax\Tracker;
103 use WPDesk\FS\TableRate\UserFeedback;
104 use WPDesk\WooCommerceCartWeight\Block\StoreEndpointData;
105
106 /**
107 * Class Flexible_Shipping_Plugin
108 */
109 class Flexible_Shipping_Plugin extends AbstractPlugin implements HookableCollection, Activateable {
110
111 use HookableParent;
112 use TemplateLoad;
113
114 /*
115 * Plugin file
116 */
117 const PLUGIN_FILE = 'flexible-shipping/flexible-shipping.php';
118
119 const PRIORITY_BEFORE_SHARED_HELPER = -35;
120 const PRIORITY_LAST = 999999;
121 const PRIORITY_AFTER_DEFAULT = 20;
122 const FS_FREE_SHIPPING_NOTICE_NAME = 'fs_free_shipping_notice';
123
124 /**
125 * Scripts version.
126 *
127 * @var string
128 */
129 private $scripts_version = '34';
130
131 /**
132 * Admin notices.
133 *
134 * @var WPDesk_Flexible_Shipping_Admin_Notices
135 */
136 public $admin_notices;
137
138 /**
139 * Default settings tab.
140 *
141 * @var string
142 */
143 private $default_settings_tab = 'connect';
144
145 /**
146 * Renderer.
147 *
148 * @var FSVendor\WPDesk\View\Renderer\Renderer;
149 */
150 private $renderer;
151
152 /**
153 * Is order processed on checkout?
154 *
155 * @var bool
156 */
157 private $is_order_processed_on_checkout = false;
158
159 /**
160 * Logger.
161 *
162 * @var LoggerInterface
163 */
164 private $logger;
165
166 /**
167 * Flexible_Invoices_Reports_Plugin constructor.
168 *
169 * @param FSVendor\WPDesk_Plugin_Info $plugin_info Plugin info.
170 */
171 public function __construct( FSVendor\WPDesk_Plugin_Info $plugin_info ) {
172 $this->scripts_version = FLEXIBLE_SHIPPING_VERSION . '.' . $this->scripts_version;
173 $this->plugin_info = $plugin_info;
174 parent::__construct( $this->plugin_info );
175 $this->init_logger();
176 $this->init_logger_on_shipment();
177 }
178
179 /**
180 * Init logger on WPDesk_Flexible_Shipping_Shipment class.
181 */
182 private function init_logger_on_shipment() {
183 // WPDesk_Flexible_Shipping_Shipment::set_fs_logger( $this->logger );
184 }
185
186 /**
187 * Init logger on WPDesk_Flexible_Shipping class.
188 *
189 * @internal
190 */
191 public function init_logger_on_shipping_method() {
192 WPDesk_Flexible_Shipping::set_fs_logger( $this->logger );
193 ShippingMethodSingle::set_fs_logger( $this->logger );
194 ShippingRate::set_fs_logger( $this->logger );
195 }
196
197 /**
198 * Initialize $this->logger
199 *
200 * @return LoggerInterface
201 */
202 private function init_logger() {
203 $logger_settings = new WPDesk_Flexible_Shipping_Logger_Settings();
204 if ( $logger_settings->is_enabled() ) {
205 add_filter( 'wpdesk_is_wp_log_capture_permitted', '__return_false' );
206
207 return $this->logger = ( new SimpleLoggerFactory( $logger_settings->get_logger_channel_name() ) )->getLogger();
208 }
209
210 return $this->logger = new NullLogger();
211 }
212
213
214 /**
215 * Load dependencies.
216 */
217 private function load_dependencies() {
218 global $wpdb;
219
220 require_once __DIR__ . '/../inc/functions.php';
221
222 $session_factory = new SessionFactory();
223
224 $this->add_hookable( new ShipmentFunctionality( $this->logger, trailingslashit( $this->get_plugin_assets_url() ) . '../vendor_prefixed/wpdesk/wp-wpdesk-fs-shipment/assets/', $this->scripts_version ) );
225
226 $this->add_hookable( new Shipment\FilterOrders() );
227 $this->add_hookable( new Shipment\ModifyStatuses() );
228 $this->add_hookable( new Shipment\DispatchLabelFile() );
229 $this->add_hookable( new Shipment\BulkAction( $session_factory ) );
230 $this->add_hookable( new Shipment\AdminNotices( $session_factory ) );
231 $this->add_hookable( new Shipment\ModifyOrderTable( $session_factory ) );
232
233 new WPDesk_Flexible_Shipping_Multilingual( $this );
234
235 $this->admin_notices = new WPDesk_Flexible_Shipping_Admin_Notices( $this );
236
237 $this->add_hookable( new WPDesk\FS\Rate\WPDesk_Flexible_Shipping_Rate_Notice() );
238
239 $this->add_hookable( new WPDesk_Flexible_Shipping_Shorcode_Unit_Weight() );
240 $this->add_hookable( new WPDesk_Flexible_Shipping_Shorcode_Unit_Dimension() );
241
242 $this->add_hookable( new AjaxHandler( trailingslashit( $this->get_plugin()->get_plugin_url() ) . 'vendor_prefixed/wpdesk/wp-notice/assets' ) );
243
244 $this->add_hookable( new WPDesk_Flexible_Shipping_Method_Created_Tracker_Deactivation_Data() );
245
246 $this->add_hookable( new ShippingIntegrations( 'flexible_shipping' ) );
247
248 $this->add_hookable( new WPDesk_Flexible_Shipping_Order_Item_Meta() );
249
250 $this->add_hookable( new Assets( trailingslashit( $this->get_plugin_url() ) . 'vendor_prefixed/wpdesk/wp-wpdesk-fs-table-rate/assets', $this->scripts_version ) );
251
252 $this->add_hookable( new NoShippingMethodsNotice(
253 current_user_can( 'manage_woocommerce' ) && 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' )
254 ) );
255
256 $this->add_hookable( new DebugTracker() );
257
258 $this->add_hookable( new PluginCompatibility() );
259
260 $this->add_hookable( new UserFeedback() );
261
262 //Onboarding
263 $setting_page_checker = new WooSettingsPageChecker();
264 $fs_methods_checker = new FlexibleShippingMethodsChecker();
265
266 $finish_option = new FinishOption();
267 $this->add_hookable( new OptionAjaxUpdater( $finish_option ) );
268 $this->add_hookable( new Onboarding(
269 $finish_option,
270 $this->scripts_version,
271 trailingslashit( $this->get_plugin_assets_url() ),
272 $setting_page_checker,
273 $fs_methods_checker
274 )
275 );
276 $this->add_hookable( new \WPDesk\FS\Onboarding\TableRate\Tracker( $finish_option ) );
277
278 $this->add_hookable( new ShippingExtensions( $this->plugin_info ) );
279
280 $this->add_hookable( new MethodTitle() );
281 $this->add_hookable( new MethodDescription( $this->renderer ) );
282 $this->add_hookable( new MethodLogoCheckoutBlocksAssets( $this->get_plugin_url(), $this->scripts_version ) );
283 $this->add_hookable( new MethodLogoSettingsField() );
284 $this->add_hookable( new MethodLogoTracker() );
285
286 $this->add_hookable( new Exporter() );
287 $this->add_hookable( new ImporterData() );
288 $this->add_hookable( new ExporterData() );
289
290 $shipping_method_management = new ShippingMethodManagement( $wpdb );
291
292 // Converter.
293 $this->add_hookable( new ConvertAction( $shipping_method_management ) );
294 $this->add_hookable( new ConvertNotice() );
295 $this->add_hookable( new ConvertTracker() );
296
297 // Duplicate FS Method.
298 $duplicator_checker = new DuplicatorChecker( $shipping_method_management );
299 $this->add_hookable( new DuplicateAction( $duplicator_checker, $shipping_method_management ) );
300 $this->add_hookable( new DuplicateNotice() );
301 $this->add_hookable( new DuplicateTracker() );
302 $this->add_hookable( new DuplicateScript(
303 trailingslashit( $this->get_plugin_assets_url() ),
304 $this->scripts_version
305 )
306 );
307
308 // Block Settings.
309 $this->add_hookable( new BlockEditing() );
310
311 $this->add_hookable( new ItemMeta() );
312
313 $this->add_hookable( new PreconfiguredScenarios\Tracker\AjaxTracker() );
314 $this->add_hookable( new PreconfiguredScenarios\Tracker\Tracker() );
315
316 // Pro Features.
317 $tracking_data = new ProFeatures\Tracker\TrackingData();
318 $this->add_hookable( new ProFeatures\Tracker\AjaxTracker( $tracking_data ) );
319 $this->add_hookable( new ProFeatures\Tracker\Tracker( $tracking_data ) );
320
321 $dashboard_tracking_data = new DashboardTrackingData();
322 $this->add_hookable( new DashboardTrackingReceiver( $dashboard_tracking_data ) );
323 $this->add_hookable( new DashboardTracker( $dashboard_tracking_data ) );
324
325 // Time tracking
326 $this->add_hookable( new \WPDesk\FS\TableRate\ShippingMethod\Timestamps\MethodTimestamps() );
327 $this->add_hookable( new \WPDesk\FS\TableRate\ShippingMethod\Timestamps\TrackerData() );
328
329 $this->add_hookable( new PluginActivation() );
330
331 $this->add_hookable( new MultipleShippingZonesMatchedSameTerritoryTracker() );
332
333 $this->add_hookable( new Tracker() );
334
335 $this->add_hookable( new ProVersionUpdateReminder( 'pl_PL' === get_locale() ) );
336
337 $this->add_hookable( new \WPDesk\FS\Plugin\PluginLinks( $this->get_plugin_file_path() ) );
338
339 $brand_assets_url = $this->get_plugin_assets_url() . '../vendor_prefixed/octolize/wp-octolize-brand-assets/assets/';
340
341 $this->add_hookable( new \WPDesk\FS\AdvertMetabox\ProPluginAdvertMetabox( $brand_assets_url ) );
342 $this->add_hookable( new \WPDesk\FS\AdvertMetabox\FsiePluginAdvertMetabox( $brand_assets_url ) );
343
344 $should_show_strategy = new ShippingMethodShouldShowStrategy( \WPDesk_Flexible_Shipping_Settings::METHOD_ID );
345 $this->add_hookable( new AdminAssets( $brand_assets_url, 'fs', $should_show_strategy ) );
346
347 // Shipping methods integration.
348 $this->add_hookable( new \WPDesk\FS\TableRate\ShippingMethodsIntegration\Integration() );
349
350 // Upgrade onboarding
351 $this->add_hookable( new WPDesk\FS\Plugin\UpgradeOnboarding( $this->plugin_info ) );
352
353 // CSAT
354 $this->add_hookable(
355 new FSVendor\Octolize\Csat\Csat(
356 new \WPDesk\FS\Csat\CsatOptionDependedOnShippingMethodAndAiUsage( 'csat_flexible_shipping_ai', 'flexible_shipping_single' ),
357 new \FSVendor\Octolize\Csat\CsatCodeFromFile( __DIR__ . '/views/csat.php' ),
358 'woocommerce_after_settings_shipping',
359 new ShippingMethodInstanceStrategy( new \WC_Shipping_Zones(), 'flexible_shipping_single' )
360 )
361 );
362
363 // Redirect woo marketplace suggestions
364 $this->add_hookable( new MarketplaceSuggestionsRedirect( $this->prepare_marketplace_suggestions_should_show_strategy() ) );
365
366 $this->initialize_docs_chat();
367
368 // Rating petition
369 add_action( 'admin_init', [ $this, 'init_rating_petition' ] );
370 }
371
372 public function init_rating_petition() {
373 if ( class_exists( '\WC_Shipping_Zones' ) ) {
374 $shipping_method_display_decision = new ShippingMethodDisplayDecision( new \WC_Shipping_Zones(), ShippingMethodSingle::SHIPPING_METHOD_ID );
375 ( new TextPetitionDisplayer(
376 'woocommerce_after_settings_shipping',
377 $shipping_method_display_decision,
378 new RepositoryRatingPetitionText(
379 'Octolize',
380 $this->plugin_info->get_plugin_name(),
381 'https://octol.io/fs-rate',
382 'center'
383 )
384 ) )->hooks();
385
386 $option_name = 'flexible-shipping-method-update-count';
387 $max_update_count = 5;
388 $option_value = (int) get_option( $option_name, 0 );
389 if ( $option_value >= $max_update_count ) {
390 $current_user = wp_get_current_user();
391 ( new PopupPetition(
392 'flexible-shipping',
393 __( 'Flexible Shipping', 'flexible-shipping' ),
394 'help@octolize.com',
395 $current_user ? $current_user->user_email : '',
396 'admin_footer',
397 $shipping_method_display_decision
398 ) )->init()->hooks();
399 }
400
401 add_action( 'flexible_shipping_method_updated', function ( $instance_id ) use ( $option_name, $max_update_count, $option_value ) {
402 if ( $option_value < $max_update_count ) {
403 update_option( $option_name, (int) get_option( $option_name, 0 ) + 1 );
404 }
405 } );
406
407 add_action( 'wpdesk_rating_petition_postpone', function ( $plugin_slug ) use ( $option_name, $max_update_count ) {
408 if ( $plugin_slug === 'flexible-shipping' ) {
409 update_option( $option_name, (int) floor( $max_update_count / 2 ) );
410 }
411 } );
412 }
413 }
414
415 /**
416 * Init contextual info on Flexible Shipping settings fields.
417 *
418 * @internal
419 */
420 public function init_contextual_info() {
421 $base_location = wc_get_base_location();
422 $base_country = $base_location['country'];
423 $contextual_info_creator = new ContextualInfo\Creator( $base_country );
424 $contextual_info_creator->create_contextual_info();
425 $contextual_info_creator->hooks();
426 }
427
428 /**
429 * Init base variables for plugin
430 */
431 public function init_base_variables() {
432 $this->plugin_url = $this->plugin_info->get_plugin_url();
433
434 $this->plugin_path = $this->plugin_info->get_plugin_dir();
435 $this->template_path = $this->plugin_info->get_text_domain();
436
437 $this->plugin_namespace = $this->plugin_info->get_text_domain();
438 $this->template_path = $this->plugin_info->get_text_domain();
439 $this->default_settings_tab = 'main';
440
441 $this->settings_url = admin_url( 'admin.php?page=flexible-shipping-settings' );
442 $this->docs_url = get_locale() === 'pl_PL' ? 'https://octol.io/fs-docs-pl' : 'https://octol.io/fs-docs';
443 }
444
445 /**
446 * Set renderer.
447 */
448 private function init_renderer() {
449 $resolver = new ChainResolver();
450 $resolver->appendResolver( new WPThemeResolver( $this->get_template_path() ) );
451 $resolver->appendResolver( new DirResolver( trailingslashit( $this->plugin_path ) . 'templates' ) );
452 $this->renderer = new FSVendor\WPDesk\View\Renderer\SimplePhpRenderer( $resolver );
453 }
454
455 /**
456 * Init.
457 */
458 public function init() {
459 $this->init_base_variables();
460 $this->init_renderer();
461 $this->load_dependencies();
462 $this->init_tracker();
463 $this->init_ai();
464 $this->hooks();
465 $this->init_assets_url_on_rules_settings_field();
466 $this->init_checkout_blocks();
467 }
468
469 /**
470 * register_activation_hook handler.
471 *
472 * @internal
473 */
474 public function activate() {
475 ( new PluginActivation() )->add_activation_option_if_not_present();
476 }
477
478 /**
479 * Hooks.
480 */
481 public function hooks() {
482 parent::hooks();
483
484 add_filter( 'woocommerce_shipping_methods', [
485 $this,
486 'woocommerce_shipping_methods_filter',
487 ], self::PRIORITY_AFTER_DEFAULT );
488
489 add_filter(
490 'flexible_shipping_method_rate_id',
491 [
492 $this,
493 'flexible_shipping_method_rate_id',
494 ],
495 9999999,
496 2
497 );
498
499 add_filter(
500 'woocommerce_shipping_chosen_method',
501 [
502 $this,
503 'woocommerce_default_shipment_method',
504 ],
505 10,
506 3
507 );
508
509 add_action(
510 'woocommerce_checkout_create_order',
511 [
512 $this,
513 'add_flexible_shipping_order_meta_on_checkout',
514 ]
515 );
516
517 add_filter( 'option_woocommerce_cod_settings', [ $this, 'option_woocommerce_cod_settings' ] );
518
519 add_action( 'woocommerce_init', [ $this, 'init_free_shipping_notice' ] );
520
521 add_action( 'woocommerce_init', [ $this, 'init_logger_on_shipping_method' ] );
522
523 add_action( 'woocommerce_init', [ $this, 'init_contextual_info' ] );
524
525 add_action( 'woocommerce_init', [ $this, 'init_shipping_zones_notice' ] );
526
527 add_action( 'woocommerce_init', [ $this, 'init_multicurrency' ] );
528
529 add_action( 'woocommerce_init', [ $this, 'init_external_plugin_access' ] );
530
531 $this->hooks_on_hookable_objects();
532 }
533
534 private function init_checkout_blocks() {
535 ( new FreeShippingBlock( [ self::FS_FREE_SHIPPING_NOTICE_NAME ] ) )->hooks();
536
537 $integration_data = ( new IntegrationData() )
538 ->set_integration_name( $this->plugin_namespace . '-free-shipping-notice-block-integration' )
539 ->set_script_name( '' )
540 ->set_script_path( '/assets/blocks/free-shipping-notice-block-integration/' );
541 ( new StoreEndpoint( $integration_data->get_integration_name(), 'page_type', false ) )->hooks();
542 ( new FreeShippingStoreEndpointData( $integration_data->get_integration_name() ) )->hooks();
543 ( new Registrator(
544 $integration_data,
545 $this->plugin_path,
546 $this->get_plugin_file_path(),
547 false,
548 false
549 ) )->hooks();
550
551 }
552
553
554 /**
555 * .
556 */
557 public function init_multicurrency() {
558 $prefix = $this->plugin_info->get_plugin_dir();
559 ( new FilterConvertersFactory( $prefix ) )->hooks();
560 ( new MultiCurrency( $this->logger, $prefix ) )->hooks();
561 }
562
563 /**
564 * .
565 */
566 public function init_external_plugin_access() {
567 do_action( 'flexible-shipping/core/initialized', new ExternalPluginAccess( $this->plugin_info->get_version(), $this->logger ) );
568 }
569
570 /**
571 * .
572 * @internal
573 */
574 public function init_shipping_zones_notice() {
575 ( new MultipleShippingZonesMatchedSameTerritoryNotice( WC()->countries, new WC_Shipping_Zones() ) )->hooks();
576 }
577
578 /**
579 *
580 */
581 private function init_assets_url_on_rules_settings_field() {
582 RulesSettingsField::set_assets_url( untrailingslashit( $this->get_plugin_assets_url() ) );
583 }
584
585 /**
586 * Init free shipping notice.
587 *
588 * @internal
589 */
590 public function init_free_shipping_notice() {
591 $cart = WC()->cart;
592 $session = WC()->session;
593 ( new FreeShippingNoticeGenerator( null, null, self::FS_FREE_SHIPPING_NOTICE_NAME ) )->hooks();
594 ( new FreeShippingNoticeRenderer( $this->renderer ) )->hooks();
595 if ( $cart instanceof WC_Cart && $session instanceof WC_Session ) {
596 ( new FreeShippingNotice( $cart, $session, self::FS_FREE_SHIPPING_NOTICE_NAME ) )->hooks();
597 ( new \WPDesk\FS\TableRate\FreeShipping\Assets( $this->get_plugin_assets_url(), $this->scripts_version ) )->hooks();
598 }
599 ( new NoticeTextSettings() )->hooks();
600 ( new ProgressBarSettings() )->hooks();
601 ( new \WPDesk\FS\TableRate\FreeShipping\Tracker() )->hooks();
602 ( new ThresholdAlertTracker() )->hooks();
603 }
604
605 /**
606 * Init tracker.
607 */
608 private function init_tracker() {
609 add_action( 'woocommerce_init', function () {
610 TrackerInitializer::create_from_plugin_info(
611 $this->plugin_info,
612 $this->prepare_shoud_display_for_flexible_shipping(),
613 new OctolizeReasonsFactory(
614 'https://octol.io/fs-docs-exit-pop-up',
615 'https://octol.io/fs-support-forum-exit-pop-up',
616 __( 'Flexible Shipping PRO', 'flexible-shipping' ),
617 'https://octol.io/fs-contact-exit-pop-up',
618 )
619 )->hooks();
620 ( new WPDesk_Flexible_Shipping_Tracker() )->hooks();
621 ( new TrackerData() )->hooks();
622 } );
623
624 }
625
626 private function init_ai() {
627 ( new TrackerDataOnShippingMethodSaver() )->hooks();
628 ( new \WPDesk\FS\TableRate\AI\TrackerData() )->hooks();
629 }
630
631 /**
632 * @return ShouldDisplayOrConditions
633 */
634 private function prepare_shoud_display_for_flexible_shipping() {
635 $should_display = new ShouldDisplayOrConditions();
636 $should_display->add_should_diaplay_condition( new ShouldDisplayShippingMethodInstanceSettings( ShippingMethodSingle::SHIPPING_METHOD_ID ) );
637 $should_display_and_conditions = new ShouldDisplayAndConditions();
638 $should_display_and_conditions->add_should_diaplay_condition(
639 new ShouldDisplayGetParameterValue( 'page', 'wc-settings' )
640 );
641 $should_display_and_conditions->add_should_diaplay_condition(
642 new ShouldDisplayGetParameterValue( 'tab', 'shipping' )
643 );
644 $should_display_and_conditions->add_should_diaplay_condition(
645 new ShouldDisplayGetParameterValue( 'section', WPDesk_Flexible_Shipping_Settings::METHOD_ID )
646 );
647 $should_display->add_should_diaplay_condition( $should_display_and_conditions );
648
649 return $should_display;
650 }
651
652 /**
653 * @return OrStrategy
654 */
655 private function prepare_marketplace_suggestions_should_show_strategy() {
656 $show_strategy = new OrStrategy(
657 new GetStrategy(
658 [
659 [
660 'page' => 'wc-settings',
661 'tab' => 'shipping',
662 'section' => WPDesk_Flexible_Shipping_Settings::METHOD_ID,
663 ],
664 ]
665 )
666 );
667
668 if ( class_exists( '\WC_Shipping_Zones' ) ) {
669 $shipping_zones = new \WC_Shipping_Zones();
670 $show_strategy->addCondition( new ShippingMethodInstanceStrategy( $shipping_zones, WPDesk_Flexible_Shipping::METHOD_ID ) );
671 $show_strategy->addCondition( new ShippingMethodInstanceStrategy( $shipping_zones, ShippingMethodSingle::SHIPPING_METHOD_ID ) );
672 }
673
674 return $show_strategy;
675 }
676
677 private function initialize_docs_chat(): void {
678 $plugin_slug = 'flexible-shipping';
679 $plugin_name = 'Flexible Shipping';
680 if ( defined( 'FLEXIBLE_SHIPPING_PRO_VERSION' ) ) {
681 $plugin_slug = 'flexible-shipping-pro';
682 $plugin_name = 'Flexible Shipping PRO';
683 }
684
685 $this->add_hookable(
686 new DocsChat(
687 $plugin_slug,
688 $this->get_plugin_url(),
689 $this->plugin_info->get_version(),
690 $this->prepare_docs_chat_should_show_strategy(),
691 new DocsChatSettingsProvider( $plugin_name )
692 )
693 );
694 }
695
696 private function prepare_docs_chat_should_show_strategy(): OrStrategy {
697 $show_strategy = new OrStrategy(
698 new ShippingMethodStrategy( \WPDesk_Flexible_Shipping_Settings::METHOD_ID )
699 );
700 $show_strategy->addCondition(
701 new ShippingMethodInstanceStrategy(
702 new \WC_Shipping_Zones(),
703 ShippingMethodSingle::SHIPPING_METHOD_ID
704 )
705 );
706
707 return $show_strategy;
708 }
709
710 /**
711 * Woocommerce shipping methods filter.
712 *
713 * @param array $methods .
714 *
715 * @return array
716 */
717 public function woocommerce_shipping_methods_filter( $methods ) {
718 $methods[ ShippingMethodSingle::SHIPPING_METHOD_ID ] = ShippingMethodSingle::class;
719 $methods[ WPDesk_Flexible_Shipping::METHOD_ID ] = WPDesk_Flexible_Shipping::class;
720
721 if ( $this->can_register_fs_info() ) {
722 $methods[ WPDesk_Flexible_Shipping_Settings::METHOD_ID ] = WPDesk_Flexible_Shipping_Settings::class;
723 }
724
725 return $methods;
726 }
727
728 /**
729 * @return bool
730 */
731 private function can_register_fs_info() {
732 if ( ! is_admin() ) {
733 return false;
734 }
735
736 return ! $this->is_adding_order_page() && ! $this->is_editing_order_page();
737 }
738
739 /**
740 * @return bool
741 */
742 private function is_editing_order_page() {
743 $post = filter_input( INPUT_GET, 'post' );
744 $action = filter_input( INPUT_GET, 'action' );
745
746 return 'edit' === $action && $post;
747 }
748
749 /**
750 * @return bool
751 */
752 private function is_adding_order_page() {
753 $action = filter_input( INPUT_POST, 'action' );
754
755 return wp_doing_ajax() && 'woocommerce_add_order_shipping' === $action;
756 }
757
758 /**
759 * Option woocommerce cod settings filter.
760 *
761 * @param array $value .
762 *
763 * @return array
764 */
765 public function option_woocommerce_cod_settings( $value ) {
766 if ( is_checkout() ) {
767 if (
768 ! empty( $value )
769 && is_array( $value )
770 && 'yes' === $value['enabled']
771 && ! empty( $value['enable_for_methods'] )
772 && is_array( $value['enable_for_methods'] )
773 ) {
774 foreach ( $value['enable_for_methods'] as $method ) {
775 if ( 'flexible_shipping' === $method ) {
776 $all_fs_methods = flexible_shipping_get_all_shipping_methods();
777 $all_shipping_methods = flexible_shipping_get_all_shipping_methods();
778 $flexible_shipping = $all_shipping_methods['flexible_shipping'];
779 $flexible_shipping_rates = $flexible_shipping->get_all_rates();
780 foreach ( $flexible_shipping_rates as $flexible_shipping_rate ) {
781 $value['enable_for_methods'][] = $flexible_shipping_rate['id_for_shipping'];
782 }
783 break;
784 }
785 }
786 }
787 }
788
789 return $value;
790 }
791
792 /**
793 * Add flexible shipping order meta on checkout.
794 *
795 * @param WC_Order $order Order.
796 */
797 public function add_flexible_shipping_order_meta_on_checkout( $order ) {
798 if ( ! $this->is_order_processed_on_checkout ) {
799 $mutex = WordpressPostMutex::fromOrder( $order );
800 $mutex->acquireLock();
801 $this->is_order_processed_on_checkout = true;
802 $order_shipping_methods = $order->get_shipping_methods();
803 foreach ( $order_shipping_methods as $shipping_id => $shipping_method ) {
804 if ( isset( $shipping_method['item_meta'] )
805 && isset( $shipping_method['item_meta']['_fs_method'] )
806 ) {
807 $fs_method = $shipping_method['item_meta']['_fs_method'];
808 if ( ! empty( $fs_method['method_integration'] ) ) {
809 $order_meta = $order->get_meta( '_flexible_shipping_integration', false );
810 if ( ! in_array( $fs_method['method_integration'], $order_meta, true ) ) {
811 $order->add_meta_data( '_flexible_shipping_integration', $fs_method['method_integration'] );
812 }
813 }
814 }
815 }
816 $mutex->releaseLock();
817 }
818 }
819
820 /**
821 * Set appropriate default FS method if no method chosen.
822 *
823 * @param string $default Default shipping method in frontend.
824 * @param WC_Shipping_Rate[] $available_methods Available methods in frontend.
825 * Function is assigned to woocommerce_default_shipment_method filter.
826 * In this parameter we expecting array of WC_Shipping_Rate objects.
827 * But third party plugins can change this parameter type or set it to
828 * null.
829 * @param string|bool|null $chosen_method If false or null then no method is chosen.
830 *
831 * @return string
832 */
833 public function woocommerce_default_shipment_method( $default, $available_methods, $chosen_method ) {
834 if ( ! is_array( $available_methods ) ) {
835 return $default;
836 }
837 if ( null === $chosen_method || false === $chosen_method ) {
838 foreach ( $available_methods as $available_method ) {
839 $method_meta = $available_method->get_meta_data();
840 if ( $method_meta && isset( $method_meta[ WPDesk_Flexible_Shipping::META_DEFAULT ] ) && 'yes' === $method_meta[ WPDesk_Flexible_Shipping::META_DEFAULT ] ) {
841 $candidate_id = $available_method->get_id();
842 if ( array_key_exists( $candidate_id, $available_methods ) ) {
843 return $candidate_id;
844 }
845 }
846 }
847 }
848
849 return $default;
850 }
851
852 /**
853 * @param string $suffix .
854 */
855 private function enqueue_rules_scripts( $suffix ) {
856 wp_register_script(
857 'fs_rules_settings',
858 trailingslashit( $this->get_plugin_assets_url() ) . 'js/rules-settings.js',
859 [ 'wp-i18n' ],
860 $this->scripts_version
861 );
862 wp_enqueue_script( 'fs_rules_settings' );
863 wp_enqueue_style(
864 'fs_rules_settings',
865 trailingslashit( $this->get_plugin_assets_url() ) . 'css/rules-settings.css',
866 [],
867 $this->scripts_version
868 );
869 wp_set_script_translations( 'fs_rules_settings', 'flexible-shipping', $this->plugin_path . '/lang/' );
870
871 }
872
873 /**
874 * Admin enqueue scripts.
875 */
876 public function admin_enqueue_scripts() {
877 if ( $this->should_enqueue_admin_scripts() ) {
878 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
879 wp_register_script(
880 'fs_admin',
881 trailingslashit( $this->get_plugin_assets_url() ) . 'js/admin' . $suffix . '.js',
882 [ 'jquery' ],
883 $this->scripts_version
884 );
885
886 $notice_url = get_locale() == 'pl_PL' ? 'https://octol.io/fs-rate-not-good-pl' : 'https://octol.io/fs-rate-not-good';
887 wp_localize_script(
888 'fs_admin',
889 'fs_admin',
890 [
891 'ajax_url' => admin_url( 'admin-ajax.php' ),
892 'notice_not_good_enought' => sprintf(
893 // Translators: link.
894 __( 'How can We make Flexible Shipping better for you? %1$sJust write to us.%2$s', 'flexible-shipping' ),
895 '<a class="button close-fs-rate-notice" target="_blank" href="' . esc_url( $notice_url ) . '">',
896 '</a>'
897 ),
898 ]
899 );
900 wp_enqueue_script( 'fs_admin' );
901
902 if ( isset( $_GET['section'] ) && WPDesk_Flexible_Shipping_Settings::METHOD_ID === sanitize_key( wp_unslash( $_GET['section'] ) ) ) {
903 add_filter( 'admin_body_class', [ $this, 'add_dashboard_admin_body_class' ] );
904 wp_enqueue_script(
905 'fs_dashboard',
906 trailingslashit( $this->get_plugin_assets_url() ) . 'js/dashboard.js',
907 [ 'heartbeat' ],
908 $this->scripts_version,
909 true
910 );
911 wp_localize_script(
912 'fs_dashboard',
913 'fsDashboardTracking',
914 [
915 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
916 'action' => DashboardTrackingReceiver::AJAX_ACTION,
917 'nonce' => wp_create_nonce( DashboardTrackingReceiver::AJAX_ACTION ),
918 ]
919 );
920 }
921
922 $current_screen = get_current_screen();
923
924 wp_register_script(
925 'wpdesk_contextual_info',
926 trailingslashit( $this->get_plugin_assets_url() ) . 'js/contextual-info' . $suffix . '.js',
927 [ 'jquery' ],
928 $this->scripts_version
929 );
930 wp_enqueue_script( 'wpdesk_contextual_info' );
931
932 if ( ! empty( $current_screen ) && 'shop_order' === $current_screen->id ) {
933 wp_enqueue_media();
934 }
935
936 wp_enqueue_style(
937 'fs_admin',
938 trailingslashit( $this->get_plugin_assets_url() ) . 'css/admin.css',
939 [],
940 $this->scripts_version
941 );
942 wp_enqueue_style(
943 'fs_font',
944 trailingslashit( $this->get_plugin_assets_url() ) . 'css/font' . $suffix . '.css',
945 [],
946 $this->scripts_version
947 );
948
949 $this->enqueue_rules_scripts( $suffix );
950
951 do_action( 'flexible-shipping/admin/enqueue_scripts', $this, $suffix );
952
953 }
954 }
955
956 /**
957 * Add body class on the Flexible Shipping info page.
958 *
959 * @param string $classes Admin body classes.
960 *
961 * @return string
962 */
963 public function add_dashboard_admin_body_class( $classes ) {
964 return $classes . ' flexible-shipping-info-page';
965 }
966
967 /**
968 * Should enqueue admin scripts?
969 */
970 private function should_enqueue_admin_scripts() {
971 $current_screen = get_current_screen();
972
973 if ( ! $current_screen ) {
974 return false;
975 }
976
977 $wc_screen_id = sanitize_title( __( 'WooCommerce', 'woocommerce' ) );
978
979 if (
980 'woocommerce_page_wc-orders' === $current_screen->id
981 || in_array( $current_screen->post_type, [ 'shop_order', 'shop_subscription', ], true )
982 || $wc_screen_id . '_page_wc-settings' === $current_screen->id
983 || 'woocommerce_page_wc-settings' === $current_screen->id ) {
984 return true;
985 }
986
987 return false;
988 }
989
990 /**
991 * Enqueue Wordpress scripts.
992 */
993 public function wp_enqueue_scripts() {
994 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
995 }
996
997 /**
998 * Links filter.
999 *
1000 * @param array $links .
1001 *
1002 * @return array
1003 */
1004 public function links_filter( $links ) {
1005 $settings_url = admin_url( 'admin.php?page=wc-settings&tab=shipping&section=' . \WPDesk_Flexible_Shipping_Settings::METHOD_ID );
1006
1007 $plugin_links = [
1008 '<a href="' . $settings_url . '">' . __(
1009 'Settings',
1010 'flexible-shipping'
1011 ) . '</a>',
1012 ];
1013
1014 if ( ! defined( 'FLEXIBLE_SHIPPING_PRO_VERSION' ) ) {
1015 $pro_link = get_locale() === 'pl_PL' ? 'https://octol.io/fs-upgrade-pl' : 'https://octol.io/fs-upgrade';
1016 $plugin_links[] = '<a href="' . esc_url( $pro_link ) . '" target="_blank" style="color:#00e3c0;font-weight:bold;">' . __(
1017 'Buy Flexible Shipping PRO',
1018 'flexible-shipping'
1019 ) . '</a>';
1020 }
1021
1022 return array_merge( $plugin_links, $links );
1023 }
1024
1025 /**
1026 * .
1027 * @param string $method_id .
1028 * @param array $shipping_method .
1029 *
1030 * @return string
1031 */
1032 public function flexible_shipping_method_rate_id( $method_id, array $shipping_method ) {
1033 if ( isset( $shipping_method['id_for_shipping'] ) && '' !== $shipping_method['id_for_shipping'] ) {
1034 $method_id = $shipping_method['id_for_shipping'];
1035 }
1036
1037 return $method_id;
1038 }
1039
1040
1041 }
1042