В вашем коде есть некоторые ошибки и ошибки ... Также вам следует избегать прописных букв в именах функций, именах переменных и слагов в php (отличается от Javascript или других языков сценариев).
Попробуйте вместо этого:
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
add_action( 'woocommerce_shipping_init', 'exec_pishtaz_shipping_method' );
function exec_pishtaz_shipping_method(){
if ( ! class_exists('WC_Shipping_Method_Pishtaz_Post') ) {
class WC_Shipping_Method_Pishtaz_Post extends WC_Shipping_Method {
public function __construct( $instance_id = 0 ){
$this->id = 'pishtaz';
$this->domain = 'pishtaz_post';
$this->instance_id = absint( $instance_id );
$this->method_title = __( 'Pishtaz post', $this->domain ) ;
$this->method_description = sprintf( __( 'sending goods with %s', $this->domain ), $this->method_title );
$this->supports = array(
'shipping-zones',
'instance-settings',
'instance-settings-modal',
);
//available country
//$this->availability = 'including';
//$this->countries = array('US');
//create from and settings
$this->init();
}
//init your setting
public function init(){
$this->init_form_fields();
$this->init_settings();
$this->enabled = $this->get_option( 'enabled', $this->domain );
$this->title = $this->get_option( 'title', $this->domain );
$this->info = $this->get_option( 'info', $this->domain );
add_action('woocommerce_update_options_shipping_' . $this->id, array($this, 'process_admin_options') );
}
public function init_form_fields(){
//our settings
$this->form_fields = array (
'title' => array(
'title' => __( 'Title' , $this->domain ),
'type' => 'text',
'description' => __( 'Title to be shown on the site', $this->domain ),
'desc_tip' => true,
'default' => __( 'pishtaz post', $this->domain )
),
'cost' => array(
'type' => 'text',
'title' => __( 'Cost', $this->domain ),
'description' => __( 'Enter a cost', $this->domain ),
'desc_tip' => true,
'default' => '',
),
);
}
public function calculate_shipping ( $packages = array() ){
$rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => '0',
'calc_tax' => 'per_item'
);
$this->add_rate( $rate );
}
}
}
}
add_filter( 'woocommerce_shipping_methods', 'add_pishtaz_shipping_method' );
function add_pishtaz_shipping_method( $methods ) {
$methods['pishtaz'] = 'WC_Shipping_Method_Pishtaz_Post';
return $methods;
}
}
Код помещается в файл function.php вашей активной дочерней темы (или темы) или также в любой файл плагина. Проверено и работает.
Чтобы сделать этот код частью другого плагина: Добавьте этот код в отдельный php-файл, который вы включите, используя следующее в своем основном файле плагина:
include_once( 'subfolder/the-php-file-name.php' );
* (где вы замените subfolder
на правильное имя подпапки (если оно существует) и the-php-file-name.php
на реальное имя файла php) *
Похожие: Создать новый способ доставки в woocommerce 3