<?php
/*
Plugin Name: Доставка Новой почтой
Plugin URI: http://woothemes.com/woocommerce
Description: Для добавления метода "Доставка Новой почтой"
Version: 1.0.0
Author: WooThemes
Author URI: http://woothemes.com
*/
/**
* Если активирован вукомерц
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
function your_shipping_method_init() {
if ( ! class_exists( 'WC_Your_Shipping_Method' ) ) {
class WC_Your_Shipping_Method extends WC_Shipping_Method {
/**
* Конструктор класса
* @access public
* @return void
*/
public function __construct() {
$this->id = 'your_shipping_method'; // Идентификатор для метода
$this->method_title = __( 'Доставка новой почтой' ); // Название в админке
$this->method_description = __( 'Метод нужен для вывода "Доставка курьерской службой "Новая почта", оплата за счет покупателя."' ); // Описание в админке
$this->enabled = "yes"; // This can be added as an setting but for this example its forced enabled
$this->title = 'Доставка курьерской службой "Новая почта", оплата за счет покупателя.'; // This can be added as an setting but for this example its forced.
$this->init();
}
/**
* Инициализация настроек
* @access public
* @return void
*/
function init() {
// Load the settings API
$this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings
$this->init_settings(); // This is part of the settings API. Loads settings you previously init.
// Save settings in admin if you have any defined
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
/**
* calculate_shipping function.
* @access public
* @param mixed $package
* @return void
*/
public function calculate_shipping( $package ) {
$rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => '0.0',
'calc_tax' => 'per_item'
);
// Register the rate
$this->add_rate( $rate );
}
// /**
// * Initialise Gateway Settings Form Fields
// */
// function init_form_fields() {
// $this->form_fields = array(
// 'title' => array(
// 'title' => __( '', 'woocommerce' ),
// 'type' => 'text',
// 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
// 'default' => __( 'PayPal', 'woocommerce' )
// ),
// 'description' => array(
// 'title' => __( 'Description', 'woocommerce' ),
// 'type' => 'textarea',
// 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce' ),
// 'default' => __("Pay via PayPal; you can pay with your credit card if you don't have a PayPal account", 'woocommerce')
// )
// );
// } // End init_form_fields()
}
}
}
add_action( 'woocommerce_shipping_init', 'your_shipping_method_init' );
function add_your_shipping_method( $methods ) {
$methods[] = 'WC_Your_Shipping_Method';
return $methods;
}
add_filter( 'woocommerce_shipping_methods', 'add_your_shipping_method' );
}
?>