【问题标题】:Woocommerce shipping method works only with billing addressWoocommerce 运输方式仅适用于帐单地址
【发布时间】: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


【解决方案1】:

问题是,在计算运费后,Woocommerce 将帖子数据重新发送到结帐页面,但没有 s_state 或 state 帖子变量。

由于我是根据这两个变量计算运费,我必须将它们保存到会话变量中并从这里计算。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 2019-05-04
    • 2014-12-22
    • 2019-06-22
    • 1970-01-01
    • 2018-11-20
    • 2021-04-21
    相关资源
    最近更新 更多