PluginProbe
DPD SK for WooCommerce / trunk
DPD SK for WooCommerce vtrunk
9.2.1 9.1.0 9.2.0 9.0.0 trunk 1.0.0 1.0.1 2.0.0 2.0.1 3.0.0 3.0.1 3.0.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 5.0.0 5.0.1 5.0.2 5.0.3 6.0.0 6.0.1 7.0.0 7.0.1 All 37 releases
wc-dpd / includes / Assets.php

Assets.php in DPD SK for WooCommerce trunk, at includes/Assets.php

89 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WcDPD;
4
5 defined('ABSPATH') || exit;
6
7 /**
8 * Assets class
9 */
10 class Assets
11 {
12 public static function init()
13 {
14 add_action('wp_enqueue_scripts', [__CLASS__, 'enqueueScripts']);
15
16 // Add the template content to the footer if WooCommerce Blocks is enabled
17 if (is_woocommerce_blocks_enabled()) {
18 add_action('wp_footer', [__CLASS__, 'addTemplateToFooter']);
19 }
20 }
21
22 /**
23 * Enqueue plugin styles and scripts
24 *
25 * @return void
26 */
27 public static function enqueueScripts()
28 {
29 if (!is_cart_or_checkout_page()) {
30 return;
31 }
32
33 $is_map_widget_enabled = is_map_widget_enabled();
34
35 // Enqueue styles
36 wp_enqueue_style('wc_dpd_parcelshop_shipping_method_content_styles', WCDPD_PLUGIN_ASSETS_URL . 'styles/dpd-parcelshop-shipping-method-content.css', [], wc_dpd_get_plugin_version(), 'all');
37
38 if ($is_map_widget_enabled) {
39 wp_enqueue_style('wc_dpd_parcelshop_map_widget_styles', WCDPD_PLUGIN_ASSETS_URL . 'styles/dpd-parcelshop-map-widget.css', [], wc_dpd_get_plugin_version(), 'all');
40 } else {
41 wp_enqueue_style('wc_dpd_parcelshop_popup_styles', WCDPD_PLUGIN_ASSETS_URL . 'styles/dpd-parcelshop-popup.css', [], wc_dpd_get_plugin_version(), 'all');
42 }
43
44 // Enqueue scripts
45 if ($is_map_widget_enabled) {
46 wp_enqueue_script('wc_dpd_parcelshop_map_scripts', 'https://pus-maps.dpd.sk/lib/library.js', [], wc_dpd_get_plugin_version(), true);
47 wp_enqueue_script('wc_dpd_parcelshop_map_widget_scripts', WCDPD_PLUGIN_ASSETS_URL . 'scripts/dpd-parcelshop-map-widget.js', [], wc_dpd_get_plugin_version(), true);
48 wp_localize_script('wc_dpd_parcelshop_map_widget_scripts', 'wc_dpd_parcelshop_map_widget_settings', [
49 'ajax_url' => admin_url('admin-ajax.php'),
50 'no_pickup_types_error_message' => __('No pickup point types are allowed. Please check the shipping settings.', 'wc-dpd'),
51 ]);
52 } else {
53 wp_enqueue_script('wc_dpd_parcelshop_popup_scripts', WCDPD_PLUGIN_ASSETS_URL . 'scripts/dpd-parcelshop-popup.js', [], wc_dpd_get_plugin_version(), true);
54 wp_localize_script('wc_dpd_parcelshop_popup_scripts', 'wc_dpd_parcelshop_popup_settings', [
55 'ajax_url' => admin_url('admin-ajax.php'),
56 'required_fields_error_message' => __('Please fill all the fields above!', 'wc-dpd'),
57 'select_parcelshop_error_message' => __('Please select one of the available parcelshops!', 'wc-dpd')
58 ]);
59 }
60
61 // Is WooCommerce Blocks enabled?
62 if (is_woocommerce_blocks_enabled()) {
63 wp_enqueue_script('wc_dpd_parcelshop_block_shipping_method_scripts', WCDPD_PLUGIN_ASSETS_URL . 'scripts/dpd-parcelshop-block-shipping-method.js', [], wc_dpd_get_plugin_version(), true);
64 wp_enqueue_style('wc_dpd_parcelshop_block_shipping_method_styles', WCDPD_PLUGIN_ASSETS_URL . 'styles/dpd-parcelshop-block-shipping-method.css', [], wc_dpd_get_plugin_version(), 'all');
65
66 // Just pass a flag to indicate the script should run
67 wp_localize_script('wc_dpd_parcelshop_block_shipping_method_scripts', 'wc_dpd_parcelshop_block_settings', [
68 'ready' => true
69 ]);
70 }
71 }
72
73 /**
74 * Add template content to footer
75 */
76 public static function addTemplateToFooter()
77 {
78 if (!is_cart_or_checkout_page()) {
79 return;
80 }
81
82 ?>
83 <div id="dpd-template-source" style="display:none;">
84 <?php echo Blocks::getTemplateContent(); ?>
85 </div>
86 <?php
87 }
88 }
89