Php Woocommerce同时提供两种配送选项

Php Woocommerce同时提供两种配送选项,php,wordpress,woocommerce,shipping,fedex,Php,Wordpress,Woocommerce,Shipping,Fedex,我有一个问题: 我有两种装运类别 1-alfa 2-测试版 阿尔法按订单(而非按产品)应为50美元,如果阿尔法产品总额(不含运费和税费)超过400美元,阿尔法运费是免费的。 我已经做到了这一点,只有当阿尔法产品和其他产品被插入到图表中时,它才能正常工作 beta应使用联邦快递配送插件进行计算,只有在将beta产品和其他产品插入图表时,该插件才能正常工作 如果我把alfa和beta产品放在图表中,我只得到alfa规则 我用树表传送插件设置规则如下: USA Child rules rate ad

我有一个问题:

我有两种装运类别

1-alfa

2-测试版

阿尔法按订单(而非按产品)应为50美元,如果阿尔法产品总额(不含运费和税费)超过400美元,阿尔法运费是免费的。 我已经做到了这一点,只有当阿尔法产品和其他产品被插入到图表中时,它才能正常工作

beta应使用联邦快递配送插件进行计算,只有在将beta产品和其他产品插入图表时,该插件才能正常工作

如果我把alfa和beta产品放在图表中,我只得到alfa规则

我用树表传送插件设置规则如下:

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

按装运类别拆分购物车,并选择“捕获”选项,以便在处理装运类别包后不会处理后续规则。创建子规则,每个规则应包含各自的装运类别,并使用“所有指定的装运类别&无其他类别”选项,以便每个规则仅适用于各自的装运类别。

按装运类别拆分购物车,并选择“捕获”选项,以便在处理装运类包后不会处理后续规则。创建子规则,每个规则应包含各自的装运类别,并使用“所有指定的&无其他”选项,以便每个规则仅适用于各自的装运类别。

明白了吗

明白了吗


没人能帮我吗?先用船运把车分开class@Mickey是的,我已经做完了。谢谢,没人能帮我吗?先把车分开装运class@Mickey是的,我已经做完了。谢谢
 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;
    }