PluginProbe
WCMultiShipping — Mondial Relay, Inpost & Chronopost for WooCommerce / trunk
WCMultiShipping — Mondial Relay, Inpost & Chronopost for WooCommerce vtrunk
3.0.7 3.0.6 3.0.5 3.0.4 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.5.0 1.6.0 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 78 releases
wc-multishipping / wc-multishipping.php

wc-multishipping.php in WCMultiShipping — Mondial Relay, Inpost & Chronopost for WooCommerce trunk, at wc-multishipping.php

168 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WCMultiShipping — Mondial Relay, Inpost & Chronopost for WooCommerce
4 Description: Create Chronopost & Mondial relay shipping labels and send them easily.
5 Version: 3.0.6
6 Author: Mondial Relay WooCommerce - WCMultiShipping
7 Author URI: https://www.wcmultishipping.com/fr/mondial-relay-woocommerce/
8 Requires Plugins: woocommerce
9 License: GPLv3
10 License URI: https://www.gnu.org/licenses/gpl-3.0.html
11 Text Domain: wc-multishipping
12 Domain Path: /languages
13 */
14
15 namespace WCMultiShipping;
16
17 use WCMultiShipping\inc\admin\classes\chronopost\chronopost_helper;
18 use WCMultiShipping\inc\admin\classes\chronopost\chronopost_pro_rest_api;
19 use WCMultiShipping\inc\admin\classes\telemetry\wms_telemetry;
20 use WCMultiShipping\inc\admin\classes\label_class;
21 use WCMultiShipping\inc\admin\classes\update_class;
22 use WCMultiShipping\inc\admin\wms_admin_init;
23 use WCMultiShipping\inc\front\wms_front_init;
24
25 defined( 'ABSPATH' ) or die( 'Sorry you can\'t...' );
26
27 if ( ! defined( 'DS' ) )
28 define( 'DS', DIRECTORY_SEPARATOR );
29 include_once __DIR__ . DS . 'inc' . DS . 'helpers' . DS . 'wms_helper_helper.php';
30
31 /*
32 * Init the plugin
33 */
34
35 function wms_init( $hook ) {
36 if (
37 ! file_exists( WPMU_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'woocommerce' . DIRECTORY_SEPARATOR . 'woocommerce.php' )
38 && ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) )
39 && ( is_multisite() && ! in_array(
40 'woocommerce/woocommerce.php',
41 apply_filters( 'active_plugins', array_keys( get_site_option( 'active_sitewide_plugins' ) ) )
42 ) )
43 )
44 return;
45
46 wms_telemetry::register_retry_hooks();
47
48 if ( is_admin() || is_network_admin() ) {
49 new wms_admin_init();
50 } else {
51 new wms_front_init();
52 }
53 }
54
55
56 add_action( 'plugins_loaded', __NAMESPACE__ . '\\wms_init', 999 );
57
58 // Chronopost PRO REST API — registered on ALL request types (including REST calls
59 // from the Chronopost PRO server, which are neither admin nor front context).
60 add_action( 'rest_api_init', function () {
61 if ( chronopost_helper::is_shipping_method_enabled() ) {
62 ( new chronopost_pro_rest_api() )->register_routes();
63 }
64 } );
65
66 add_action( 'init', function () {
67
68 //Used to submit translations to WP
69 $translations = [
70 __( 'Generate outward labels', 'wc-multishipping' ),
71 __( 'Download labels', 'wc-multishipping' ),
72 __( 'Print labels', 'wc-multishipping' ),
73 __( 'Delete labels', 'wc-multishipping' ),
74 __( "Display pickup points map via", "wc-multishipping" ),
75 __( "Automatically generate label on these order status", "wc-multishipping" ),
76 __( "Status to set after label generation", "wc-multishipping" ),
77 __( "Send tracking link via email once the label is generated?", "wc-multishipping" ),
78 __( 'Click here to ship this order with %s', 'wc-multishipping' )
79 ];
80
81 } );
82
83
84 // Hook: Frontend assets.
85 add_action( 'enqueue_block_assets', function () {
86
87 if ( ! function_exists( 'register_block_type' ) || ( ! is_checkout() && ! has_block( 'woocommerce/checkout' ) ) ) {
88 // Gutenberg is not active.
89 return;
90 }
91
92 // Use the centralized asset manager
93 $asset_manager = \WCMultiShipping\inc\helpers\classes\wms_asset_manager::get_instance();
94 $asset_manager->register_pickup_scripts();
95
96 $shipping_providers = [ "chronopost", "mondial_relay", "ups" ];
97 $providers_config = [];
98 $google_maps_is_used = $mondial_relay_map_is_used = $open_street_maps_is_used = false;
99
100 foreach ( $shipping_providers as $one_shipping_provider ) {
101 $map_type = get_option( 'wms_' . $one_shipping_provider . '_section_pickup_points_map_type', 'openstreetmap' );
102
103 if ( "google_maps" == $map_type && $google_maps_is_used == false ) {
104 $google_maps_is_used = true;
105 $google_maps_api_key = get_option( 'wms_' . $one_shipping_provider . '_section_pickup_points_google_maps_api_key' );
106 $providers_config[ $one_shipping_provider ] = 'google_maps';
107 } elseif ( "mondial_relay_map" == $map_type ) {
108 $mondial_relay_map_is_used = true;
109 $providers_config[ $one_shipping_provider ] = 'mondial_relay_map';
110 } elseif ( "openstreetmap" == $map_type ) {
111 $open_street_maps_is_used = true;
112 $providers_config[ $one_shipping_provider ] = 'openstreetmap';
113 }
114 }
115
116 //Load Country listing (displayed in the modals)
117 global $woocommerce;
118 $countries_obj = new \WC_Countries();
119 $countries = $countries_obj->__get( 'countries' );
120
121 global $post;
122
123 if ( ! has_block( "woocommerce/checkout", $post->post_content ) && ! is_checkout() )
124 return;
125
126 // Use the asset manager to enqueue all necessary scripts
127 $asset_manager->enqueue_pickup_scripts( $providers_config );
128
129 // Include modals
130 if ( $google_maps_is_used ) {
131 include WMS_SHARED_PARTIALS . 'pickups' . DS . 'google_maps' . DS . 'modal.php';
132 }
133
134 if ( $mondial_relay_map_is_used ) {
135 include WMS_SHARED_PARTIALS . 'pickups' . DS . 'mondial_relay' . DS . 'modal.php';
136 }
137
138 if ( $open_street_maps_is_used ) {
139 include WMS_SHARED_PARTIALS . 'pickups' . DS . 'openstreetmap' . DS . 'modal.php';
140 }
141
142 // Enqueue CSS
143 wp_enqueue_style( 'wms_pickup_CSS', WMS_SHARED_CSS_URL . 'pickups/wooshippping_pickup_widget.min.css', [], \WCMultiShipping\inc\helpers\classes\wms_asset_manager::get_version() );
144 } );
145
146
147
148 add_action( 'woocommerce_blocks_loaded', function () {
149 require_once __DIR__ . '/wcmultishipping-blocks-integration.php';
150 add_action(
151 'woocommerce_blocks_checkout_block_registration',
152 function ($integration_registry) {
153 $integration_registry->register( new \Wcmultishipping_Blocks_Integration() );
154 }
155 );
156 } );
157
158 //__START__free_
159 /*
160 * Activation hook
161 */
162 register_activation_hook( __FILE__, function() {
163 update_class::create_wms_db();
164 // Set transient to trigger redirect to welcome page
165 set_transient( 'wms_activation_redirect', true, 30 );
166 } );
167 //__END__free_
168