public static function get_instance() { if (null == self::$instance) { self::$instance = new self(); } return self::$instance; }
public function save_delivery_points($post_id) { $order = wc_get_order($post_id); $shipping_method = WC_Edostavka::get_order_shipping_method($order); if (isset($_POST['delivery_point']) && strpos($shipping_method, 'edostavka_') === 0) { $old = get_post_meta($post_id, '_delivery_point', true); $new = $_POST['delivery_point']; if ($new && $new != $old) { update_post_meta($post_id, '_delivery_point', $new); $order->add_order_note(sprintf(__('Пункт выдачи заказа: %s'), $new)); $this->trigger_email_notification($order); } elseif ('' == $new && $old) { delete_post_meta($post_id, '_delivery_point', $old); } } }
public function get_content_plain() { ob_start(); woocommerce_get_template($this->template_plain, array('order' => $this->object, 'email_heading' => $this->get_heading(), 'message' => $this->get_message(), 'points' => WC_Edostavka::get_delivery_points($this->object->billing_state), 'sent_to_admin' => false, 'plain_text' => true), '', $this->template_base); return ob_get_clean(); }
public function calculate_shipping($package = array()) { if ($this->enabled_in_cart !== 'yes' && is_cart()) { return; } $rates = array(); $errors = array(); $shipping_values = $this->edostavka_calculate($package); if (!empty($shipping_values)) { $chosen_method = null; foreach ($shipping_values as $code => $shipping) { if (!isset($shipping['result'])) { continue; } if ($this->replace_shipping_label_door === 'yes' && WC_Edostavka::wc_edostavka_delivery_tariffs_type($code) === 'door') { $name = $this->shipping_label_door; } elseif ($this->replace_shipping_label_stock === 'yes' && WC_Edostavka::wc_edostavka_delivery_tariffs_type($code) === 'stock') { $name = $this->shipping_label_stock; } else { $name = WC_Edostavka_Connect::get_service_name($code); } $price = $shipping['result']['price']; $label = 'yes' == $this->display_date ? WC_Edostavka_Connect::estimating_delivery(apply_filters('woocommerce_edostavka_label_name', $name), $shipping['result']['deliveryPeriodMax'], $this->additional_time) : $name; $cost = $this->fix_format(esc_attr($price)); $fee = $this->get_fee($this->fix_format($this->fee), $cost); array_push($rates, array('id' => $this->id . '_' . $code, 'label' => $label, 'cost' => $cost + $fee)); $chosen_method = $this->id . '_' . $code; } $rates = apply_filters('woocommerce_edostavka_shipping_methods', $rates, $package); if ($this->autoselect_edostavka_shipping_method === 'yes' && $chosen_method !== null) { WC()->session->set('chosen_shipping_methods', array($chosen_method)); } if (sizeof($rates) > 0) { foreach ($rates as $rate) { $this->add_rate($rate); } if (is_cart() && 'yes' == $this->show_notice) { wc_add_notice($this->notice_text, 'notice'); } } else { if (is_checkout() && strpos(WC_Edostavka::get_chosen_shipping_method(), $this->id) === 0 && 'yes' == $this->show_error) { wc_add_notice($this->error_text, 'error'); } } } }
public static function get_service_name($code) { $name = WC_Edostavka::wc_edostavka_delivery_tariffs(); if (!isset($name[$code])) { return ''; } return $name[$code]; }