0
どのように特定の都市の重量に基づいて出荷方法を作るには?特定都市のwoocommerce出荷方法は、重量に基づいて
例えば、1kgあたり1ドルで都市「A」の郵便料金を払いたいとします。ここで
は私が作ったプラグインのコードです:
public function calculate_shipping($package) {
$rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => '10.99',
'calc_tax' => 'per_item'
);
// Register the rate
$this->add_rate($rate);
}
全コード:問題はcalculate_shipping
である
<?php
/*
Plugin Name: Trucking shipping
Plugin URI: http://abdhannan.com
Description: Trucking shipping dengan JNE dsb
Version: 1.0.0
Author: Abd Hannan
Author URI: http://abdhannan.com
*/
/**
* Check if WooCommerce is active
*/
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
function trucking_shipping_init() {
if (! class_exists('WC_Your_Shipping_Method')) {
class WC_trucking_shipping_Method extends WC_Shipping_Method {
/**
* Constructor for your shipping class
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'trucking_shipping_method'; // Id for your shipping method. Should be uunique.
$this->method_title = __('JNE TRUCKING'); // Title shown in admin
$this->method_description = __('Pengiriman dengan truck JNE'); // Description shown in admin
$this->enabled = "yes"; // This can be added as an setting but for this example its forced enabled
$this->title = "JNE TRUCKING"; // This can be added as an setting but for this example its forced.
$this->init();
}
/**
* Init your settings
*
* @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' => '10.99',
'calc_tax' => 'per_item'
);
// Register the rate
$this->add_rate($rate);
}
}
}
}
add_action('woocommerce_shipping_init', 'trucking_shipping_init');
function add_trucking_shipping_method($methods) {
$methods['trucking_shipping_method'] = 'WC_trucking_shipping_Method';
return $methods;
}
add_filter('woocommerce_shipping_methods', 'add_trucking_shipping_method');
}
、私は私がやりたいのか分かりません。
はい、右thatsの、と私はすべての出荷ゾーンに作成する必要があり、使用テーブル率のプラグインを持っていますが、私の国であり、多くのzhippingゾーン(500以上)、 は はそう、私が欲しいです発送方法は自動的に条件を計算し、データは元のfom jsonファイルになります。 誰でも助けてくれますか? –
あなたが500の出荷ゾーンを実装しようとしているなら、あなたは何か間違ったことをしています。毎回出荷を簡素化するために、常に最善を尽くしてください。たとえば、郵便番号の場合は、範囲を使用する必要があります。 – Kodaloid
Hmmm、あなたは正しいです 要件と私自身のプラグインを作ることは不可能ですか?ここに参考ペーストがあれば、どうぞ。 –