WooCommerce الحصول على جميع API طريقة حسابها Shiping

أحاول إنشاء وظائف API للجوال للحصول على طرق الشحن من WordPress WooCommerce. هذه هي شفرتي:

    public function get_shipping($request){
        $params = (array) json_decode(file_get_contents('php://input'), TRUE);
        $state =  $params['state'];
        $country =  $params['country'];
        global $woocommerce;
        $woocommerce->cart->empty_cart();
        foreach ($params['line_items'] as $item) {
           if((int) $item["variation_id"] > 0 ){
               $woocommerce->cart->add_to_cart(
                   (int)  $item["id"],
                   (int) $item["quantity"],
                   $item["variation_id"]);
           } else {
               $woocommerce->cart->add_to_cart(
                   (int)  $item["id"],
                   (int) $item["quantity"]);
           }
        }

        $package =  $woocommerce->cart->get_shipping_packages();
        $delivery_zones = (Array) WC_Shipping_Zones::get_zones();
        $new_delivery_zones = Array();
        foreach ($delivery_zones as $zone) {
            $z_object =  (Array) $zone;
            $new_shippings = Array();
            foreach ($z_object["shipping_methods"] as $shipping) {
                $s_item = Array();
                $objects = (Array) $shipping;
                foreach ($objects as $key => $value) {
                    if($key != "instance_form_fields") {
                        $s_item[$key] = $value;
                    }else{
                        $f_item = Array();
                        $new_form_fields = Array();
                        $form_fields = (Array) $value;
                        foreach ($form_fields as $keyi => $valuei) {
                            $valuei["name"] = $keyi;
                            $f_item[$keyi] = $valuei;
                            array_push($new_form_fields, $valuei);
                        }
                        $s_item["instance_form_fields"] = $new_form_fields;
                    }
                }
                array_push($new_shippings, $s_item);

            }
            $z_object["shipping_methods"] = null;
            $z_object["shipping_methods"] = $new_shippings;
            array_push($new_delivery_zones, $z_object);

        }

        $correct_zone = null;
        foreach ($new_delivery_zones as $zone) {
            foreach ($zone["zone_locations"] as $location) {
                 $splits = explode(":",$location-> code);
                 if(count($splits) > 1){
                     $country = $splits[0];
                     $code = $splits[1];
                     if($country == $country && $code == $state ){
                         $correct_zone = $zone;
                     }
                 }
            }
        }
        if($correct_zone == null)
            return $correct_zone;

        $package['destination']['country'] = $country;
        $package['destination']['state'] = (int) $state;
        $package['destination']['country'] = $country;
        $new_shipping_method = Array();
        foreach ($correct_zone["shipping_methods"] as $shipping_method) {
            if (class_exists($shipping_method["id"])) {
                $class = new $shipping_method["id"]();
                $class->calculate_shipping_for_package($package);

                foreach ($class->rates as $rate) {
                    array_push($shipping_method["rates"], Array(
                        "cost" => $rate->cost,
                        "label" => $rate->label,
                        "method_id" => $rate->method_id
                    ));
                }
//                error_log(print_r($class->rates, true));
                array_push($new_shipping_method, $shipping_method);
            }else{
                array_push($new_shipping_method, $shipping_method);
            }
        }
        $correct_zone["shipping_methods"] = $new_shipping_method;

        return $correct_zone;
    }

and I'm reading this post

ولكن لم أفهم أين تكمن المشكلة ، لأنها لا تعمل بشكل صحيح ولا تتطابق أسعارها المحسوبة مع المكونات الإضافية.

من فضلك من فضلك أعطني الرمز الصحيح شكرا جزيلا

0