'Παραλαβή από ACS Points',//'Collection from an ACS Point', 'checkout_button_label' => 'Επιλέξτε ένα ACS Point',//'Select an ACS Point', 'checkout_validation_error' => 'Please select a pickup point', 'checkout_validation_error_weight' => 'We are sorry. %s is not possible for orders of %d kg and higher.', 'checkout_selected_point_title' => "You've selected to pick up your order from", 'email_selected_point_title' => 'Selected ACS SmartPoint', ]; static $configuration = [ 'checkout_input_name' => 'acs_pp_point_id', 'post_meta_field_name' => 'acs_pp_point', ]; public function __construct() { $this->settings = self::getSettings(); if ($this->settings['enabled'] === 'yes') { $this->initWoo(); } } function initWoo() { add_action('woocommerce_review_order_before_cart_contents', array($this, 'pre_checkout_validation'), 10); add_action('woocommerce_after_checkout_validation', array($this, 'checkout_validation'), 10, 2); add_action('woocommerce_before_checkout_form', array($this, 'add_map_in_checkout'), 10, 1); add_action('woocommerce_after_shipping_rate', array($this, 'add_map_trigger_to_shipping_option'), 10, 2); add_action('woocommerce_after_order_notes', array($this, 'add_checkout_point_input')); add_action('woocommerce_checkout_update_order_meta', array($this, 'save_checkout_point_input')); add_action('woocommerce_order_details_after_customer_details', array($this, 'show_point_details_in_customer'), 10); add_action('woocommerce_admin_order_data_after_billing_address', array($this, 'show_point_details_in_admin'), 10, 1); add_action(ACS_POINTS_PLUGIN_ID . 'cron_hook', array($this, 'fetch_points_json')); } public static function getSettings() { $settings = get_option('woocommerce_acs-points-plugin_settings'); if (empty($settings)) { $settings = array('enabled' => 'no'); } if (isset($settings['baseCost']) && !isset($settings['pricing']['overland']['baseCost'])) { $settings['pricing']['overland']['baseCost'] = $settings['baseCost']; } if (isset($settings['baseCostKgLimit']) && !isset($settings['pricing']['overland']['baseCostKgLimit'])) { $settings['pricing']['overland']['baseCostKgLimit'] = $settings['baseCostKgLimit']; } if (isset($settings['costPerKg']) && !isset($settings['pricing']['overland']['costPerKg'])) { $settings['pricing']['overland']['costPerKg'] = $settings['costPerKg']; } return $settings; } public function get_order_weight() { $chosen_methods = WC()->session->get('chosen_shipping_methods'); $packages = WC()->shipping->get_packages(); $weight = 0; foreach ($packages as $i => $package) { if ($chosen_methods[$i] != ACS_POINTS_PLUGIN_ID) { continue; } foreach ($package['contents'] as $item_id => $values) { $_product = $values['data']; if (is_numeric($_product->get_weight())) { $weight += $_product->get_weight() * $values['quantity']; } } } return (float)wc_get_weight($weight, 'kg'); } public function pre_checkout_validation() { $chosen_methods = WC()->session->get('chosen_shipping_methods'); if (!is_array($chosen_methods)) { return; } if (!in_array(ACS_POINTS_PLUGIN_ID, $chosen_methods)) { return; } $weightLimit = (int)$this->settings['weightUpperLimit']; if ($weightLimit == 0) { return; } $weight = $this->get_order_weight(); if ($weight > $weightLimit) { $message = sprintf( __(self::$labels['checkout_validation_error_weight'], ACS_POINTS_PLUGIN_ID), __(self::$labels['checkout_option_title'], ACS_POINTS_PLUGIN_ID), $weightLimit ); $messageType = "error"; if (!wc_has_notice($message, $messageType)) { wc_add_notice($message, $messageType); } } } public function checkout_validation($data, $errors) { if ( ACS_POINTS_PLUGIN_ID == $data['shipping_method'][0] && empty($_POST[self::$configuration['checkout_input_name']]) ) { $errors->add('validation', __(self::$labels['checkout_validation_error'], ACS_POINTS_PLUGIN_ID)); } $weightLimit = (int)$this->settings['weightUpperLimit']; if ($weightLimit != 0 && $this->get_order_weight() > $weightLimit) { $errors->add('validation', sprintf( __(self::$labels['checkout_validation_error_weight'], ACS_POINTS_PLUGIN_ID), __(self::$labels['checkout_option_title'], ACS_POINTS_PLUGIN_ID), $weightLimit )); } } public function add_map_in_checkout() { $googleMapsKey = $this->settings['googleMapsKey']; $filesPath = '/wp-content/plugins/acs-points/'; wp_enqueue_script(ACS_POINTS_PLUGIN_ID . '-js-googleapis', 'https://maps.googleapis.com/maps/api/js?key=' . $googleMapsKey . '&libraries=geometry', array(), ACS_POINTS_PLUGIN_VERSION, 'all'); wp_enqueue_script(ACS_POINTS_PLUGIN_ID . '-js-markerclusterer', plugins_url('js/markerclusterer.js', __FILE__), array(), ACS_POINTS_PLUGIN_VERSION, 'all'); wp_enqueue_script(ACS_POINTS_PLUGIN_ID . '-js-woo-script', plugins_url('js/woo-script.js', __FILE__), array(), ACS_POINTS_PLUGIN_VERSION, 'all'); wp_enqueue_script(ACS_POINTS_PLUGIN_ID . '-js-script', plugins_url('js/script.js', __FILE__), array(), ACS_POINTS_PLUGIN_VERSION, 'all'); wp_enqueue_style(ACS_POINTS_PLUGIN_ID . '-css-styles', plugins_url('css/styles.css', __FILE__), array(), ACS_POINTS_PLUGIN_VERSION, 'all'); require 'acs-points-map.php'; } public function add_map_trigger_to_shipping_option($method) { if ($method->id == ACS_POINTS_PLUGIN_ID) { $buttonLabel = __(self::$labels['checkout_button_label'], ACS_POINTS_PLUGIN_ID); echo '