0
私はWooCommerce用の非常に小さく簡単なカスタム配送方法を作成しました。基本的には都市と重量に基づいて配送料金が計算されます。WoCommerceの配送方法は、請求先住所でのみ動作します
class WC_Chilexpress_Shipping_Method extends WC_Shipping_Method {
...
public function calculate_shipping($package){
$small_price = get_post_meta($shipping[0]->ID, 'chxp_small_price', true);
$medium_price = get_post_meta($shipping[0]->ID, 'chxp_medium_price', true);
if($weight < 6 && $weight >= 3) :
$cost = $medium_price + 1000;
elseif($weight < 10 && $weight >= 6) :
$cost = $medium_price + 1700;
elseif ($weight >= 10) :
$cost = $medium_price + 2200;
elseif($weight < 3) :
$cost = (int)$small_price + 700;
endif;
$this->add_rate(array(
'id' => $this->id,
'label' => $this->title,
'cost' => $cost
));
return $cost;
}
すべてが罰金のみ請求先住所を使用して動作しますが、チェックアウトは「店でピックアップ」を選択したと言う「配送先住所」を選択している場合。
完全なコードはここにある:
https://gist.github.com/albertojm/55a9319dadc36c936c84a3904d114fbd
https://gist.github.com/albertojm/8e2e3fe2d90e19dc1875ef04ab565125
コードをプラグインとして使用していますか?このチュートリアルのコードを修正しましたか(https://waseem-senjer.com/shipping-method-for-woocommerce-development-tutorial/)? – LoicTheAztec
私はそれに似たコードを採用しました(私が見つけた場所を思い出すことはできません)。 – Alberto