【发布时间】:2016-08-07 21:54:11
【问题描述】:
我为 WooCommerce 创建了一个非常小而简单的自定义运输方法,它基本上根据城市和重量计算运输成本。
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
【问题讨论】:
-
您是否将您的代码用作插件?代码from this tutorial修改了吗?
-
我已经修改了一个类似的代码(不记得我在哪里找到的)。
标签: wordpress woocommerce