【问题标题】:Woocommerce two shipping options at same timeWoocommerce 同时提供两种运输方式
【发布时间】:2017-01-23 00:40:34
【问题描述】:

我有一个问题:

我有两个运输类别

1- 阿尔法

2- 测试版

alfa 应为 50 美元(不是按产品),如果 alfa 产品总和(不含运费和税费)超过 400 美元,则 alfa 运费是免费的。 我已经完成了这条规则,它只有在 alfa 产品且没有其他产品插入图表时才能正常工作。

beta应该使用fedEx shipping plugin来计算,它只有在beta产品并且没有其他产品插入图表时才能正常工作。

如果我将 alfa 和 beta 产品放入图表中,我只会得到 alfa 规则。

我用 Tree Table shipping 插件这样设置规则:

USA 
Child rules rate add sum of child rates

   ALFA
   Package all items at once
   Contains specified and maybe others ALFA any amount
   Calculate fees for all matching items at once
   Other shipping plugins FEDEX add all rates

   BETA
   Contains specified and maybe others BETA subtotal without tax and discount below 400$
   Charge Flat Fee 50$

   BETA
   Contains specified and maybe others BETA subtotal without tax and discount above 400$
   Free shipping

【问题讨论】:

  • 没人能帮我吗?
  • 先按运输等级拆分购物车
  • @Mickey 是的,我已经完成了。谢谢

标签: php wordpress woocommerce shipping fedex


【解决方案1】:

按运输类别拆分购物车,并选择“捕获”选项,以便在处理运输类别包裹后不会处理后续规则。创建子规则,每个规则都应包含其各自的运输类别,并将“全部指定且无其他”选项,以便每条规则仅适用于其各自的运输类别。

【讨论】:

    【解决方案2】:

    收到snippet from here

     add_filter( 'woocommerce_cart_shipping_packages', 'wf_split_cart_by_shipping_class_group' );
    
        function wf_split_cart_by_shipping_class_group($packages){
    
            //Reset packages
            $packages               = array();
    
            //Init splitted package
            $splitted_packages      =   array();
    
            // Group of shipping class ids
            $class_groups   =   array(
                'group1'    =>  array(9,10),
                'group2'    =>  array(20),
                'group3'    =>  array(11,15,17),        
            );  
    
            // group items by shipping classes
            foreach ( WC()->cart->get_cart() as $item_key => $item ) {
                if ( $item['data']->needs_shipping() ) {
    
                    $belongs_to_class_group =   'none';
    
                    $item_ship_class_id =   $item['data']->get_shipping_class_id();
    
                    if($item_ship_class_id){
    
                        foreach($class_groups as $class_group_key   =>  $class_group){
                            if(in_array($item_ship_class_id, $class_group)){                
                                $belongs_to_class_group =   $class_group_key;
                                continue;
                            }
                        }
    
                    }           
    
                    $splitted_packages[$belongs_to_class_group][$item_key]  =   $item;
                }
            }
    
            // Add grouped items as packages 
            if(is_array($splitted_packages)){
    
                foreach($splitted_packages as $splitted_package_items){
                    $packages[] = array(
                        'contents'        => $splitted_package_items,
                        'contents_cost'   => array_sum( wp_list_pluck( $splitted_package_items, 'line_total' ) ),
                        'applied_coupons' => WC()->cart->get_applied_coupons(),
                        'user'            => array(
                             'ID' => get_current_user_id(),
                        ),
                        'destination'    => array(
                            'country'    => WC()->customer->get_shipping_country(),
                            'state'      => WC()->customer->get_shipping_state(),
                            'postcode'   => WC()->customer->get_shipping_postcode(),
                            'city'       => WC()->customer->get_shipping_city(),
                            'address'    => WC()->customer->get_shipping_address(),
                            'address_2'  => WC()->customer->get_shipping_address_2()
                        )
                    );
                }
            }
    
            return $packages;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-20
      • 2014-06-03
      • 1970-01-01
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      • 2019-02-03
      • 1970-01-01
      相关资源
      最近更新 更多